Maximo Integration

Expand all | Collapse all

Need to Extend Maximo work issuing processes to cover third party work dispatching.

  • 1.  Need to Extend Maximo work issuing processes to cover third party work dispatching.

    Posted 23 days ago
    Hi Team,

    I have an requirement like this: Email(s) should be triggered to vendor once the Work Order status is moved to DESPATCHED and Vendors can have multiple contacts and emails,the email template will be based on the jobplan.

    Here is my code:
    ----------------------
    from psdi.mbo import MboConstants
    from psdi.server import MXServer

    if mbo.isModified("status") and mbo.getString("status") == "DESPATCHED":
        vendor=mbo.getString("VENDOR")

        whereClause="COMPANY='"+ vendor +"'"
        companiesSet=mbo.getMboSet("$WO_VENDOR",'COMPANIES',whereClause)

        whreClause="COMPANY='"+ vendor +"'"
        compcontactSet=mbo.getMboSet("$WO_CONTACT",'COMPCONTACT',whreClause)

         for i in range(0,compcontactSet.count()):
             email=compcontactSet.getMbo(i).getString("EMAIL")
             if email is not None:
                   jpnum=mbo.getString("JPNUM")
                   wherclause="KA_JPNUM='"+ jpnum +"'"
                   commtemplateSet = mbo.getMboSet("$commtemp","COMMTEMPLATE",wherclause)
                   templateid=commtemplateSet.getMbo(0).getString("TEMPLATEID")
                   commtemplatesendtoSet=MXServer.getMXServer().getMboSet("COMMTMPLTSENDTO",MXServer.getMXServer().getSystemUserInfo())
                   newcommtmplt=commtemplatesendtoSet.add()
                   if newcommtmplt is not None:
                         newcommtmplt.setValue("TEMPLATEID",templateid)
                         newcommtmplt.setValue("TYPE","EMAIL")
                         newcommtmplt.setValue("SENDTO","1")
                         newcommtmplt.setValue("SENDTOVALUE",email,MboConstants.NOACCESSCHECK)
                   commtemplatesendtoSet.save()
                   commtemplateSet.getMbo(0).sendMessage(mbo,mbo)

    I am unable to change the status of work order when the script is active.It was displaying an system message :

    owner#NoOwnerFound.

    Can anyone help me on this .
    Thanks in Advance.

    Regards,
    Anuja.




    ------------------------------
    Anuja Dhanekula
    ------------------------------


  • 2.  RE: Need to Extend Maximo work issuing processes to cover third party work dispatching.

    Posted 22 days ago
    I'm assuming the issue is that you're retrieving the COMMTMPLTSENDTO when it expects to have COMMTEMPLATE as the owner record since those two go together. COMMTMPLTSENDTO is used when you have roles/people that you want to send the communication automatically when the template is referenced. In your case you need to adjust the commlog record, not the commtemplate record. 

    You want something like this:
            commLogSet = mbo.getMboSet("COMMLOG")
            commlogMbo = commLogSet.addAtEnd(ownerMbo.NOACCESSCHECK)
            commlogMbo.copyFromTemplate(commtemplate)

    And then from there modify the sendto and such fields on commlogMbo to contain the email addresses you want. When you're done just call
    commlogMbo.sendMessage() to send the email.
    Not related to your issue, but some suggestions to potentially make the code cleaner and more efficient. 
        whereClause="COMPANY='"+ vendor +"'"
        companiesSet=mbo.getMboSet("$WO_VENDOR",'COMPANIES',whereClause)

    Because you have the vendor attribute on the mbo, you can simply reference it like below. This also handles any issues that might require parameterization (such as a single quote in the company name). You should also provide an ORGID filter since company is at an org level (you could have two different companies in two different organizations with the same value for company)

    companiesSet=mbo.getMboSet("$WO_VENDOR",'COMPANIES',"company=:vendor")

    I also try and avoid "for i in range(0,compcontactSet.count()):". Executing a count means a separate database query has to occur to get the number of records and you don't need to do that. You can iterate over the set a variety of ways. For example, you could do
    i=0
    compcontactMbo=compcontactSet.getMbo(i)
    while compcontactMbo:
        i+=1
        compcontactMbo=compcontactSet.getMbo(i)

    or what I often do, especially when I control the set (like you do here)
    compcontactMbo=compcontactSet.moveFirst()
    while compcontactMbo:
        compcontactMbo=compcontactSet.moveNext()


    ------------------------------
    Steven Shull
    Director of Development
    Projetech Inc
    Cincinnati OH
    ------------------------------



  • 3.  RE: Need to Extend Maximo work issuing processes to cover third party work dispatching.

    Posted 22 days ago
    Hi Steven Shull,

    Thank you for all the inputs you suggested.
    I have modified the script as needed but unable to send mail where as I found an error in log.

    Error:

    AttributeError: 'NoneType' object has no attribute 'NOACCESSCHECK' in <script> at line number 22

    Script:
    --------
    from psdi.mbo import MboConstants
    from psdi.server import MXServer
    email=""
    ownerMbo=mbo.getOwner()
    if mbo.isModified("status") and mbo.getString("status") == "DESPATCHED":
           vendor=mbo.getString("VENDOR")
           whereClause="COMPANY='"+ vendor +"'"
           companiesSet=mbo.getMboSet("$WO_VENDOR",'COMPANIES',whereClause)
            whreClause="COMPANY='"+ vendor +"'"
            compcontactSet=mbo.getMboSet("$WO_CONTACT",'COMPCONTACT',whreClause)
            compcontactMbo=compcontactSet.moveFirst()
            while (compcontactMbo):
                   email=compcontactMbo.getString("EMAIL")
                   print "Email Received in to while loop:" +email
                   compcontactMbo=compcontactSet.moveNext()
    if email is not None:
            jpnum=mbo.getString("JPNUM")
            wherclause="KA_JPNUM='"+ jpnum +"'"
            commtemplateSet = mbo.getMboSet("$commtemp","COMMTEMPLATE",wherclause)
            templateid=commtemplateSet.getMbo(0).getString("TEMPLATEID")
            commLogSet = mbo.getMboSet("COMMLOG")
            commlogMbo = commLogSet.addAtEnd(ownerMbo.NOACCESSCHECK)#line number 22
            commlogMbo.copyFromTemplate(templateid)
            if commlogMbo is not None:
                        commlogMbo.setValue("TEMPLATEID",templateid)
                        commlogMbo.setValue("SENDTO",email,MboConstants.NOACCESSCHECK)
                         commlogMbo.sendMessage()
    Could you please help me resloving this .
    Thanks and Regards,
    Anuja.



    ------------------------------
    Anuja Dhanekula
    ------------------------------



  • 4.  RE: Need to Extend Maximo work issuing processes to cover third party work dispatching.

    Posted 22 days ago
    Hi Steven Shull,

    In addition to above the post I have received another error after changing line number 22 as
    commlogMbo = commLogSet.addAtEnd(MboConstants.NOACCESSCHECK)

    Error:
    TypeError: copyFromTemplate(): 1st arg can't be coerced to psdi.mbo.MboRemote in <script> at line number 23

    Thanks in advance.

    Regards,
    Anuja


    ------------------------------
    Anuja Dhanekula
    ------------------------------



  • 5.  RE: Need to Extend Maximo work issuing processes to cover third party work dispatching.

    Posted 22 days ago
    Sorry, I was modifying example code we had to match yours but missed switching ownerMbo (which is what I had in one of my scripts) to mbo.NOACCESSCHECK. You're getting an error because ownerMbo wasn't declared.

    As for your second error, commtemplate in my scenario is the communication template MBO. Drop the getString("TEMPLATEID") and you should be fine. 

    You also don't need to set the template (commlogMbo.setValue("TEMPLATEID",templateid)) as that will be done automatically by doing the copyFromTemplate. 

    ------------------------------
    Steven Shull
    Director of Development
    Projetech Inc
    Cincinnati OH
    ------------------------------



  • 6.  RE: Need to Extend Maximo work issuing processes to cover third party work dispatching.

    Posted 17 days ago
    Hi Steven Shull,

    I have performed changes as you mentioned.
    commlogMbo.copyFromTemplate(getString("TEMPLATEID"))
    After performing this change I am receiving an error.

    NameError: name 'getString' is not defined in <script> at line number 23

    And can you help me with copyFromTemplate method ,in which scenarios we use this.
    Many Thanks,
    Anuja.Dhanekula.



    ------------------------------
    Anuja Dhanekula
    ------------------------------



  • 7.  RE: Need to Extend Maximo work issuing processes to cover third party work dispatching.

    Posted 17 days ago
    In your code above, you had this:
    templateid=commtemplateSet.getMbo(0).getString("TEMPLATEID")

    When I said drop getString("TEMPLATEID"), I meant drop it (not place it somewhere else). You can't have a string, you need a communication template MBO. So you would have:

    templateid=commtemplateSet.getMbo(0)

    Then from there your previous script would work as 

    commlogMbo.copyFromTemplate(templateid)


    ------------------------------
    Steven Shull
    Director of Development
    Projetech Inc
    Cincinnati OH
    ------------------------------



  • 8.  RE: Need to Extend Maximo work issuing processes to cover third party work dispatching.

    Posted 14 days ago
    Hi Steven Shull,
    Thank you very much .All your inputs had helped in resolving the mistakes. Thanks again for getting back to me so quickly.
    Best Regards,
    Anuja.Dhanekula.

    ------------------------------
    Anuja Dhanekula
    ------------------------------