Sidebar

How can I use a JSON template with evaluateTemplate?

0 votes
624 views
asked Feb 28, 2018 by brandon-w-8204 (33,270 points)
I want to use a JSON template with evaluateTemplate and I keep getting a blank result. What is the syntax to use evaluateTemplate with a JSON template?

1 Answer

0 votes

Because JSON uses brackets as part of the syntax you have to escape the node tags as well as specify isJSON as true on the evaluateTemplate.

Here is sample JSON template.

{
  "hardCodedValue": "value",
  "messageCacheValue": "/*{mc:testValue}*/"
}

Here is sample code for the evaluate template

//Add a value to the messageCache for evaluateTemplate to replace
messageCache.setValue('testValue', 'someValue');
//Get system variable 'jsonTemplate' and evaluate the nodetag /*{mc:testValue}*/
var json = qie.evaluateTemplate(qie.getVariable('jsonTemplate'), null, null, true);
//set the message to the evaluated value.
message.setNode('/', qie.parseJSONString(json));

 

answered Feb 28, 2018 by brandon-w-8204 (33,270 points)
...