Maximo

Maximo

Come for answers, stay for best practices. All we're missing is you.

 View Only
  • 1.  Pass variable from automation script to communication template

    Posted Wed November 17, 2021 06:09 PM
    Edited by System Admin Wed March 22, 2023 11:52 AM
    MAM 7.6.1.2:

    I have an automation script that checks for issues and sends emails via communication templates:
    Escalation: Email me if external web service returns any records (JSON) or if service is down

    ctMboSet = mbo.getMboSet("$commtemp", "COMMTEMPLATE", "TEMPLATEID ='GISWO_ERROR'")
    ctMbo = ctMboSet.getMbo(0)
    ctMbo.sendMessage(mbo, mbo)​

    The emails that are sent are helpful, but they could be better.
    Ideally, the emails would contain information like "Error 500 - Internal Server Error". Or, "there are 50 records that haven't been synced".

    Is there a way to pass variables from an automation script to a communication template? (so that the emails can have more descriptive information)

    Thanks.


    #AssetandFacilitiesManagement
    #Maximo


  • 2.  RE: Pass variable from automation script to communication template

    Posted Thu November 18, 2021 05:58 AM
    You can use attributes placeholders with the object you have chosen in the communication template and they will be replaced automatically when you send the message.

    Alternatively, you can put a custom placeholder in your template, i.e. @REPLACE_EMAIL, and replace manually in your automation script.

    Here is a exemple where I send a table of PRLINES in PR approval process:
    def mountPrLineMessage(mbo):
    	global table;
    	global tableBodyLine;
    
    	prLineSet = mbo.getMboSet("PRLINE");
    
    	messagePrLine = " - ";
    	tableBkp = table;
    
    	if not prLineSet.isEmpty():
    
    		prLine = prLineSet.moveFirst();
    		messagePrLine = "@prlines";
    
    
    		while prLine is not None:
    			description = "";
    			comment = "";
    
    			contractLine = prLine.getMboSet("CONTRACTREFLINE").moveFirst();
    
    			contract = contractLine.getMboSet("CONTRACT").moveFirst();
                    
    			prLineReplaceBkp = tableBodyLine;
    			prLineReplaceBkp = prLineReplaceBkp.replace('&lt;','<');
    			prLineReplaceBkp = prLineReplaceBkp.replace('&gt;','>');
    			prLineReplaceBkp = prLineReplaceBkp.replace('&quot;','"');
    			prLineReplaceBkp = prLineReplaceBkp.replace('<div>&nbsp;</div>','');
    			prLineReplaceBkp = prLineReplaceBkp.replace('</div><div>','');
    			prLineReplaceBkp = prLineReplaceBkp.replace('<br />','');
    			prLineReplaceBkp = prLineReplaceBkp.replace('<!-- RICH TEXT -->','');
                #these replaces come from a table that I have created in another point
    			prLineReplaceBkp = prLineReplaceBkp.replace('@contract', contract.getString("EBSCONTRACTNUM"));
    			prLineReplaceBkp = prLineReplaceBkp.replace('@line', contractLine.getString("CONTRACTLINENUM"));
    			prLineReplaceBkp = prLineReplaceBkp.replace('@qty', prLine.getString("ORDERQTY"));
    			prLineReplaceBkp = prLineReplaceBkp.replace('@unit', prLine.getString("ORDERUNIT"));
    			prLineReplaceBkp = prLineReplaceBkp.replace('@itemnum', prLine.getString("ITEMNUM"))
    			prLineReplaceBkp = prLineReplaceBkp.replace('@description', contractLine.getString("DESCRIPTION"));
    			prLineReplaceBkp = prLineReplaceBkp.replace('@comment', contractLine.getString("ITEMCOMMENT"));
    			prLineReplaceBkp = prLineReplaceBkp  + '@prlines';
    
    			messagePrLine = messagePrLine.replace('@prlines',prLineReplaceBkp).replace('<!-- RICH TEXT -->','');
    			
    			prLine = prLineSet.moveNext();
    
    	return tableBkp.replace('@prlines', messagePrLine).replace('@prlines', ''); ​


    I hope this script can help you.

    Regards,
    Maycon




    ------------------------------
    Maycon Belfort
    Consultant
    Maxinst Consultoria e Tecnologia LTDA
    Belo Horizonte
    Brazil
    ------------------------------



  • 3.  RE: Pass variable from automation script to communication template

    Posted Sat November 20, 2021 08:05 AM
    Edited by System Admin Wed March 22, 2023 11:52 AM
    For what it's worth, a colleague pointed out that line #3 below can be used:

    ctMboSet = mbo.getMboSet("$commtemp", "COMMTEMPLATE", "TEMPLATEID ='LINR'")
    ctMbo = ctMboSet.getMbo(0)
    ctMbo.setValue("SUBJECT", desc, MboConstants.NOACCESSCHECK | MboConstants.NOVALIDATION_AND_NOACTION)
    ctMbo.sendMessage(mbo, mbo)

    But that actually updates the COMMTEMPLATE record/table, which isn't quite what I'm looking for.

    #AssetandFacilitiesManagement
    #Maximo


  • 4.  RE: Pass variable from automation script to communication template

    Posted Mon November 22, 2021 06:55 AM
    Yes, in this case it will update the template. What you can do is save the previous subject value and then after send the message, update it back with another setValue.

    ------------------------------
    Maycon Belfort
    Consultant
    Maxinst Consultoria e Tecnologia LTDA
    Belo Horizonte
    Brazil
    ------------------------------



  • 5.  RE: Pass variable from automation script to communication template

    Posted Mon November 22, 2021 08:47 AM

    You can create a commlog (get the set and add to it) and use the copyFromTemplate method to bring in the values from the template to override it. Something like:

    clMbo=mbo.getMboSet("COMMLOG").add()
    clMbo.copyFromTemplate(ctMbo)
    clMbo.setValue("SUBJECT","My New Subject")
    clMbo.sendMessage()

    It's more verbose but allows you to override everything before sending, including adding attachments or who the email gets sent to for example. 



    ------------------------------
    Steven Shull
    ------------------------------



  • 6.  RE: Pass variable from automation script to communication template

    Posted Sat November 20, 2021 09:01 PM
    Edited by System Admin Wed March 22, 2023 11:47 AM
    It turns out we already had an automation script that does the kind of thing that I'm looking for.

    Similar to the “placeholder” idea --- it manually replaces “placeholder” strings in the commtemplate with the desired content (in this case, fields from a WO), then sends the email. It doesn’t permanently alter the content of the commtemplate.

    Comm template:



    Relevant parts of the script:

    ….
    from psdi.common.commtmplt import CommTemplateRemote
    …..
    commSetRemote = mxe.getMboSet("COMMTEMPLATE", mbo.getUserInfo())
    commSetRemote.setFlag(MboConstants.DISCARDABLE, True)
    commSetRemote.setWhere("templateid='" + "CGNAPAREQ" + "'")
    oCommTemplate = commSetRemote.getMbo(0)
    …..
    sToEmailAddress1 = []
    sToEmailAddress = oCommTemplate.convertSendTo("COMMTMPLT_SENDTOROLE",oCommTemplate)
    sFromEmailAddress = oCommTemplate.getString('SENDFROM')
    sToEmailAddress1 = sToEmailAddress.split(",")
    ….
    subject  = oCommTemplate.getString('SUBJECT')
    subject = subject.replace(":wonum", mbo.getString('WONUM'))
    ……
    sMessage = oCommTemplate.getString("MESSAGE")
    …..
    sMessage = sMessage.replace(":WONUM", mbo.getString('WONUM'))
    sMessage = sMessage.replace(":reportedby", mbo.getString('reportedby'))
    sMessage = sMessage.replace(":description", mbo.getString('description'))
    sMessage = sMessage.replace(":changeby", mbo.getString('changeby'))
    sMessage = sMessage.replace(":assetnum", mbo.getString('assetnum'))
    sMessage = sMessage.replace(":asset.classstructure.hierarchypath", mbo.getString('asset.classstructure.hierarchypath'))
    sMessage = sMessage.replace(":Asset.SERIALNUM", mbo.getString('asset.SERIALNUM'))
    sMessage = sMessage.replace(":ASSET.cgmanufacturer", mbo.getString('asset.cgmanufacturer'))
    sMessage = sMessage.replace(":asset.description", mbo.getString('asset.description'))
    
    …..
    
    MXServer.sendEMail(sToEmailAddress1, sFromEmailAddress,subject, sMessage)
    
    …….
    ​

    #Maximo
    #AssetandFacilitiesManagement


  • 7.  RE: Pass variable from automation script to communication template

    Posted Tue November 23, 2021 12:45 PM
    I would use a psdi.mbo.SqlFormat to do all the substitutions.

    ------------------------------
    Blessings,
    Jason Uppenborn
    Sr. Technical Maximo Consultant
    Cohesive Ontracks
    ------------------------------



  • 8.  RE: Pass variable from automation script to communication template

    Posted Wed March 16, 2022 06:02 PM
    Hi 
    so the simplest way to do this would be 
    1. add non persistent attributes to the "mbo".
    2. use the automation script to set those np attributes
    3. bind those attributes to the comm template

    Effectively use the "mbo" to pass the script variables.

    ------------------------------
    Anamitra Bhattacharyya
    IBM
    Bedford MA
    ------------------------------