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('<','<');
prLineReplaceBkp = prLineReplaceBkp.replace('>','>');
prLineReplaceBkp = prLineReplaceBkp.replace('"','"');
prLineReplaceBkp = prLineReplaceBkp.replace('<div> </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
------------------------------
Original Message:
Sent: Wed November 17, 2021 06:09 PM
From: User1971
Subject: Pass variable from automation script to communication template
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
elif result is None: #Comm Template GISWO_ERROR: "The web service had an error." # "Check for WOs that have not been synced to Maximo." 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)
(I like using communication templates for my emails...they're easy/clean to manage.)
Thanks.
#Maximo
#AssetandFacilitiesManagement