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.

Incident Email Interaction Add Work Log

Incident Email Interaction Add Work Log


from psdi.mbo import SqlFormat
from psdi.server import MXServer
from psdi.common.emailstner import LSNRUtil
from psdi.common.emailstner import LSNRHTMLTagRemover

print "INC_MFMAIL_ADDWORKLOG - BEGIN"

objectkey = mbo.getString("OBJECTKEY")
strclass = mbo.getString("OBJECTNAME")
personid = mbo.getString("PERSONID")
subject = mbo.getString("SUBJECT")
tmpbody = mbo.getString("MSGBODY")

tagRemover = LSNRHTMLTagRemover()
msgbody = tagRemover.removeTag(tmpbody)

if (objectkey==''):
    strstart = "[["
    strend = "]]"
    startpos = subject.find(strstart) + len(strstart)
    endpos = subject.find(strend, startpos)
    ticketid = subject[startpos:endpos]
    mbo.setValue("OBJECTKEY", ticketid)
else:
    ticketid = objectkey

if (strclass==''):
    strclass="INCIDENT"

strkey = "WORKLOG_DESCRIPTION="
worklogldesc = ''
inpos = msgbody.find(strkey)
if (int(inpos) > 0):
    strnewline = ";"
    startpos = msgbody.find(strkey) + len(strkey)
    endpos = msgbody.find(strnewline, startpos)
    worklogldesc = msgbody[startpos:endpos]

strkey = "WONUM="
wonum = ''
inpos = msgbody.find(strkey)
if (int(inpos) > 0):
    strnewline = ";"
    startpos = msgbody.find(strkey) + len(strkey)
    endpos = msgbody.find(strnewline, startpos)
    wonum = msgbody[startpos:endpos]

strkey = "WO_DESCRIPTION="
wodesc = ''
inpos = msgbody.find(strkey)
if (int(inpos) > 0):
    strnewline = ";"
    startpos = msgbody.find(strkey) + len(strkey)
    endpos = msgbody.find(strnewline, startpos)
    wodesc = msgbody[startpos:endpos]

#Change Activity Status
strkey = "ACTIVITY_COMPLETED="
activitystatus = ''
inpos = msgbody.find(strkey)
if (int(inpos) > 0):
    strnewline = ";"
    startpos = msgbody.find(strkey) + len(strkey)
    endpos = int(startpos) + 1
    activitystatus = msgbody[startpos:endpos]

if (wonum <> ''):
    tmp = "E-mail Update from activity #" + wonum + " (" + wodesc + ")"
    worklogdesc = tmp[:100]
    sqlf = SqlFormat("ticketid=:1")
    sqlf.setObject(1, "INCIDENT", "TICKETID", ticketid)
    incidentSet = mbo.getMboSet("$incident", "INCIDENT", sqlf.format())
    incidentMbo = incidentSet.getMbo(0)

    if (incidentMbo is not None):
        worklogSet = incidentMbo.getMboSet("WORKLOG")
        worklogMbo = worklogSet.add()
        worklogMbo.setValue("DESCRIPTION", worklogdesc)
        worklogMbo.setValue("DESCRIPTION_LONGDESCRIPTION", worklogldesc)
   
    #Change Activity Status
    sqlf2 = SqlFormat("wonum=:1 and origrecordid=:2")
    sqlf2.setObject(1, "WOACTIVITY", "WONUM", wonum)
    sqlf2.setObject(2, "INCIDENT", "TICKETID", ticketid)
    activitySet = mbo.getMboSet("$woactivity", "WOACTIVITY", sqlf2.format())
    activityMbo = activitySet.getMbo(0)

    if (activityMbo is not None):
        mxServer = MXServer.getMXServer()
        statusmemo = "EMAILUPDATE"
        current_actstatus = activityMbo.getString("STATUS")
        if (str(activitystatus) <> '1' and current_actstatus <> 'INPRG' and current_actstatus <> 'COMP' and current_actstatus <> 'CLOSE'):
            activityMbo.changeStatus("INPRG", mxServer.getDate(), statusmemo)
        elif (str(activitystatus) == '1' and current_actstatus <> 'COMP' and current_actstatus <> 'CLOSE'):
            if (current_actstatus <> 'INPRG'):
                activityMbo.changeStatus("INPRG", mxServer.getDate(), statusmemo)
            activityMbo.changeStatus("COMP", mxServer.getDate(), statusmemo)

#print "Mark Complete"
attrarray = ["status"]
keyarray = ["COMPLETE"]
newmbo = LSNRUtil.updateInboundComm(attrarray, keyarray, mbo)

print "INC_MFMAIL_ADDWORKLOG - END"