Technical Blog Post
Abstract
Deleting DOCLINKS with Automation Scripting
Body
Contributors: Steve Hauptman, Ted Lyons, Mike Sielian, John Cook, Melody Bienfang
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);
Define an Action in the Actions Application
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
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.
UID
ibm11132773