IBM Support

Deleting DOCLINKS with Automation Scripting

Technical Blog Post


Deleting DOCLINKS with Automation Scripting


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



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. 
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 import File
from java.rmi import RemoteException
from psdi.mbo import *
from psdi.mbo import MboConstants
from psdi.util import MXException
from import Docinfo
from import DocinfoSet
from import DocinfoSetRemote
from 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+"'")

	print('**** DOCINFOID... '+docinfoid)

	k = 0
	commlogdoc = commlogdocsSet.getMbo(k)
	while (commlogdoc is not None):
		urlname = commlogdoc.getString("URLNAME")
		deleteCfile = File(urlname)
		k = k+1
		commlogdoc = commlogdocsSet.getMbo(k);

# 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)
		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):
			docinfo = docinfoSet.getMbo(j)
			while (docinfo != None):
				if (isCommLogOwner(doclink)):
					print('**** deletefilefromserver... ')
				docinfo = docinfoSet.getMbo(j);	
		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.


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.


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



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



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.




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



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":"BU005","label":"IoT"}, "Product":{"code":"SSLKT6","label":"Maximo Asset Management"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":""}]