Variable in Reply Template are not substituted per scripts

Hi, 

I have created reply template and implemented in crm scripts, if Ticket Status to closed changed, then Message to Customer with that Template.

But If I checked Emails, the Variables are not substituted:

 

Why?

here my script:

#setLanguageLevel 3;
Void SendMSG(String ticketId, String to, String cc, String bcc, String subject, String body)
{
Message msg;
msg.setValue("ticketId", ticketId);
Vector vTO;
vTO.parseString(to,",");
Vector vCC;
vCC.parseString(cc,",");
Vector vBCC;
vBCC.parseString(bcc,",");
//msg.addHeader("to", to);
msg.setValue("emailHeader", "Test");
msg.setValue("subject", subject);
//msg.setValue("body", body);
msg.setValue("type", "html");
msg.setValue("bodyHtml", body);
msg.save();
msg.send(vTO, vCC, vBCC, subject, body);
}

String ticketId = getVariable("ticketId");
Ticket t;
t.load(ticketId.toInteger());
String subject = t.getValue("title");
NSPersonAgent myPersonAgent;
NSPerson myPerson = myPersonAgent.GetPerson(t.getValue("cust_id").toInteger());
String emailTo = myPerson.GetEmail();
Integer rtId = 52; //User reply_template for closing Ticket
ReplyTemplate replyTemplate;
replyTemplate.load(rtId);
String subject2 = replyTemplate.getSubject(0) + " - (MBS Support ID: " + ticketId + ") "+ subject;
String body = replyTemplate.getHtmlBody(0);
String oldStatus = getParserVariable("ticket.old.ticketStatus");
String newStatus = getParserVariable("ticket.new.ticketStatus");
if ((oldStatus != "2") && (oldStatus != "7") && ((newStatus == "2") || (newStatus == "7"))) {
SendMSG(ticketId, emailTo, "", "", subject2, body);
}

 

Thanks a lot!

RE: Variable in Reply Template are not substituted per scripts

Hi Jianchun, you need to get a Parser, f.instance via getParser(), and pass the body through it to replace the variables.

Von: Frode Lillerud 18. Feb 2020

RE: Variable in Reply Template are not substituted per scripts

Hi Frode,

Thanks!

yes it works now:

String ticketId = getVariable("ticketId");
Ticket t;
t.load(ticketId.toInteger());
Parser parser = getParser();
t.toParser(parser);

...

String subject2 = parser.parseString(replyTemplate.getSubject(0)) + " - (MBS Support ID: " + ticketId + ") "+ subject;
String body = parser.parseString(replyTemplate.getHtmlBody(0));

Von: Jianchun You 18. Feb 2020