(SOLVED) Using a template to send a message through scripting - using template variables

Hi community.

Using CRM scripting I've succesfully managed to use the Email and Message class. Hovever I've havent yet figured a method of translating template variables to actual values, if I want to use an existing reply template. 

I guess it have something to to with parsing the relevant data for the ticket, customer etc., but I'm struggeling with getting it to work. Or I could manually analyze the body of the reply template, but that seems a bit tedious.

Any out there with some ideas?

I'm developing on SO8.0SR4.

RE: Using a template to send a message through scripting - using template variables

Hi Kasper, unless I have misunderstood your question, you want to use a reply template and replace the template variables (e.g customer.name, ticket.title, and so on) to actual values?

Well, you can use the parser and send the various objects to the parse and it will return the correct output, something like this:

 

Ticket t;
t.load(getVariable("ticketId").toInteger());

Customer c;
c.load(t.getValue("custId").toInteger());

Parser p;
t.toParser(p);
c.toParser(p);

Integer rtId = 123;
ReplyTemplate rt;
rt.load(rtId);

String subject = p.parseString(rt.getSubject(0));
String body = p.parseString(rt.getHtmlBody(0));

//...
Av: Simen Mostuen Iversen 18. dec 2017

RE: Using a template to send a message through scripting - using template variables

Hi Simen.

I think this is exactly what I'm looking for. I had the dots, I just needed to connect them in the right order.

Thank you!

Av: Kasper Rosenlund 18. dec 2017