The web blog http://www.learnsccd.com strives to be a comprehensive guide to SCCD, TADDM, SERVICE NOW and MAXIMO tools. This is a personal site maintained solely by me. I intend to update it regularly.For live updates please follow us on.

Automation Script to delete Doclinks in Maximo

Automation Script to delete Doclinks in Maximo

Automation Script to delete Doclinks in Maximo

The script gives clients the flexibility to delete attached documents (DOCLINKS) seamlessly and with ease. By existing functionality in Maximo namely Escalations and Automation Scripting,we can purge attached documents from the location where the document physically stores. A selection criteria should be defined in an Escalation (e.g. STATUS = 'CLOSED') along with an Action which invokes a Jython script that will physically delete the document from the server.

Jython script provided here is generic and can be applied to any object (Workorder, Incident, SR etc).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 are physically deleted.


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

# Check if the docslink 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


# Delete the COMMLOG doc physically from the server.
def deletecommlogfilesfromserver(docsinfo):

    docinfoid = docsinfo.getString("DOCINFOID")
    commlogdocsSet = MXServer.getMXServer().getMboSet("COMMLOGDOCS", docsinfo.getUserInfo())
    commlogdocsSet.setWhere("DOCINFOID = '"+docinfoid+"'")
    commlogdocsSet.reset()

    print('DOCINFOID... '+docinfoid)

    k = 0
    commlogdocs = commlogdocsSet.getMbo(k)
    while (commlogdocs is not None):
        urlname = commlogdocs.getString("URLNAME")
        deleteCfile = File(urlname)
        if(deleteCfile.exists()):
            deleteCfile.delete();
        k = k+1
        commlogdocs.delete(MboConstants.NOACCESSCHECK)
        commlogdocs = commlogdocsSet.getMbo(k);
    #commlogdocsSet.deleteAll(MboConstants.NOACCESSCHECK)
    commlogdocsSet.save(MboConstants.NOACCESSCHECK)


#delete the file from the server.
def deletefilefromserver(docsinfo):
    urlname = docsinfo.getString("URLNAME")
    deletefile = File(urlname)
    if (deletefile.exists()):
        print('Deleting file... '+urlname)
        deletefile.delete()
        print('File Deleted... '+urlname)
       

print 'Starting docslink delete ..'

#Action MBO get the associated DocslinkSet based on the 'DOCLINKS' relationship.
docslinkSet = mbo.getMboSet("DOCLINKS")

if docslinkSet is not None:
    i = 0
    docslink = docslinkSet.getMbo(i)
    while (docslink != None):
        docsinfoSet = docslink.getMboSet("DOCINFO")
        if (docsinfoSet is not None):
            j=0
            docsinfo = docsinfoSet.getMbo(j)
            while (docsinfo != None):
                if (isCommLogOwner(docslink)):
                    deletecommlogfilesfromserver(docsinfo)
                else:
                    print('Deleting file from server........')
                    deletefilefromserver(docsinfo)
                    docsinfo.delete(MboConstants.NOACCESSCHECK)
                docslink.delete(MboConstants.NOACCESSCHECK)   
                j=j+1
                docsinfo = docsinfoSet.getMbo(j);   
        i=i+1
        docslink = docslinkSet.getMbo(i);

Create Script in the Automation Script Application
1) Select "Script with Action Launch Point".
2) Give the name like "DOCLINKS"and note it down because,We will need it when defining the Action in the next step.
3) Set the fields as defined in the image below.
4) Cut and paste the Jython code from the "Code" section in the above

Create Action:
1.Go To->System Configuration->Platform Configuration ->Actions.
2.Create a new action as mentioned below.
 The Parameter/Attribute has to the be the same name as the Script name created in the above.