IBM Support

Deleting DOCLINKS with Automation Scripting

Technical Blog Post


Abstract

Deleting DOCLINKS with Automation Scripting

Body

Contributors: Steve Hauptman, Ted Lyons, Mike Sielian, John Cook, Melody Bienfang

 

 

Introduction
 
This post describes a technical solution that gives clients the flexibility to delete attached documents (DOCLINKS) seamlessly and with ease. By leveraging existing functionality in Maximo namely Escalations and Automation Scripting, you can purge attached documents from the location where the document physically lives. A selection criteria should be defined in an Escalation  (e.g. STATUS = 'CLOSED') along with an Action which invokes a Python script (described in this post)  that will physically delete the document from the server.
 
The Python script provided in this post is generic and can be applied to any object (Workorder, Incident, SR etc). Although we recommend this script be used with an Escalation and an Action launch point, it can be used with other launch points as well. In addition to deleting the document from the server the script will also cleanup the entries in the Doclinks and other related tables. There will be no "orphaned" records lingering after the file is physically deleted. The script addresses direct attachments as well as attachments uploaded via Communication Templates and CommLog. 
 
Disclaimer
 
Finally before we get into the details please note that this solution should not be deployed directly into a production environment before testing and making sure it fits the client's use case. The script does not contain any business rules or any sort of validation. It simply deletes the file and cleans the Doclink table. It is up to the client to decide when to invoke the script by defining the appropriate escalation criteria and frequency.
 

Python Code

  from psdi.common.action import ActionCustomClass    from java.io import File  from java.rmi import RemoteException  from psdi.mbo import *  from psdi.mbo import MboConstants  from psdi.util import MXException  from psdi.app.doclink import Docinfo  from psdi.app.doclink import DocinfoSet  from psdi.app.doclink import DocinfoSetRemote  from psdi.app.doclink import DoclinksSetRemote  from java.lang import SecurityException  from psdi.server import MXServer  import sys        # COMMENT: function to check if the doclink owner is a commlog or the main mbo.  def isCommLogOwner(doclink):  	ownertable = doclink.getString("OWNERTABLE")  	print('**** OWNERTABLE... '+ownertable)  	if (ownertable) == "COMMLOG":  		return True  	return False      # COMMENT: function to delete the commlog doc physical file from the server.  def deletecommlogfilefromserver(docinfo):    	docinfoid = docinfo.getString("DOCINFOID")  	commlogdocsSet = MXServer.getMXServer().getMboSet("COMMLOGDOCS", docinfo.getUserInfo())  	commlogdocsSet.setWhere("DOCINFOID = '"+docinfoid+"'")  	commlogdocsSet.reset()    	print('**** DOCINFOID... '+docinfoid)    	k = 0  	commlogdoc = commlogdocsSet.getMbo(k)  	while (commlogdoc is not None):  		urlname = commlogdoc.getString("URLNAME")  		deleteCfile = File(urlname)  		if(deleteCfile.exists()):  			deleteCfile.delete();  		k = k+1  		commlogdoc.delete(MboConstants.NOACCESSCHECK)  		commlogdoc = commlogdocsSet.getMbo(k);  	#commlogdocsSet.deleteAll(MboConstants.NOACCESSCHECK)  	commlogdocsSet.save(MboConstants.NOACCESSCHECK)      # COMMENT: function to delete the physical file from the server.  def deletefilefromserver(docinfo):  	urlname = docinfo.getString("URLNAME")  	deletefile = File(urlname)  	if (deletefile.exists()):  		print('**** Deleting file... '+urlname)  		deletefile.delete()  		print('**** File Deleted... '+urlname)  		    print 'Starting doclink delete .....'    # COMMENT: from the Action MBO get the associated DoclinksSet based on the 'DOCLINKS' relationship.  doclinksSet = mbo.getMboSet("DOCLINKS")    if doclinksSet is not None:  	i = 0  	doclink = doclinksSet.getMbo(i)  	while (doclink != None):  		docinfoSet = doclink.getMboSet("DOCINFO")  		if (docinfoSet is not None):  			j=0  			docinfo = docinfoSet.getMbo(j)  			while (docinfo != None):  				if (isCommLogOwner(doclink)):  					deletecommlogfilefromserver(docinfo)  				else:  					print('**** deletefilefromserver... ')  					deletefilefromserver(docinfo)  					docinfo.delete(MboConstants.NOACCESSCHECK)  				doclink.delete(MboConstants.NOACCESSCHECK)	  				j=j+1  				docinfo = docinfoSet.getMbo(j);	  		i=i+1  		doclink = doclinksSet.getMbo(i);

 

Defining the Automation Script in the Automation Scripts Application
 
Launch the Automation Script App and ....
 
1) Select "Script with Action Launch Point" - you're going to be launching this script from an Action.
 
image

 

 
2) Give it a name like DOCLINKS or something and note it down because you'll need it when defining the Action in the next step. I used Workorder but you can set the Object to whatever is applicable.
 

image

 
 
3) Set the fields as defined in the image below. 

 

image

 
 
 
4) Cut and paste the python code from the "Code" section in blue above
 
 

image

 
 

Define an Action in the Actions Application

Go to the Actions app and create a new action like this ...

The Parameter/Attribute has to the be the same name as the Script name created in the step above.

 

image

 

Define the Escalation

Go to the Escalation Application and define an Escalation with the appropriate condition and reference points that fit your use case. Here is a link on how to set up an escalation

 

Conclusion

This is a pretty powerful solution for those seeking to delete DOCLINK attachments within Maximo. There is no need to deploy any compiled code or bring down the server to take advantage of this solution. 

 

 

[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSLKT6","label":"IBM Maximo Asset Management"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

UID

ibm11132773