Skip to content

qie.evaluateTemplate

Signature: qie.evaluateTemplate(template, parameters*, escapeFor*, isJSON*, endpointURL*, alternateMessages*)

Returns: String evaluatedTemplate - the result of evaluating the template and replacing node tags with values

Evaluates the template and replaces each node path tag (e.g. {PID-5}) with the corresponding value from the specified source node, message node, message cache, or system variable.

Parameters

Type Name Description Default
String template the template string with the embedded node tags
Map<String, String> parameters* (optional) a list of parameters to use when evaluating the template with node tag 'p' null
String escapeFor* (optional) the character escaping method to use when evaluating the template ('csv', 'html', 'sql' or 'xml') null
Boolean isJSON* (optional) set to true if current message format is JSON false
String endpointURL* (optional) the endpointUrl that will replace the '%%ENDPOINT_URL%%' system node tag in the template null
Message or Message[] alternateMessages* (optional) the Messages(s) to be used with node tag 'alt' or 'alt-#' null

Example

// evaluateTemplate Examples:
// Example: template with parameters map, JSON output, and current message values
message = qie.createJSONMessage('{"weight":"300lb"}');

var jsonTemplate = '' +
   '{' +
   '  "name":"/*{p:name}*/",' +
   '  "age":"/*{p:age}*/",' +
   '  "weight":"/*{m:weight}*/"' +
   '}';

var params = qie.newParameterMap();
params.put("name", "Jonathan Jones");
params.put("age", "48");

var evaluatedJson = qie.evaluateTemplate(
   jsonTemplate,  // template
   params,        // parameters
   null,          // escapeFor
   true           // isJSON (whether or not the template is JSON)
);


// Example: template with escapeFor = "html"
var htmlTemplate = "Patient: {p:name}<br/>Message: {m:text}";
message = qie.createJSONMessage('{"text":"<cartoon>Tom & Jerry </cartoon>"}');

var htmlParams = qie.newParameterMap();
htmlParams.put("name", "Alice & Bob");

var evaluatedHtml = qie.evaluateTemplate(
   htmlTemplate,  // template
   htmlParams,    // parameters
   "html",        // escapeFor
   false          // isJSON (whether or not the template is JSON)
);


// Example: template with endpointURL
var endpointTemplate = "Posting to %%ENDPOINT_URL%% for patient {p:name}";
var endpointParams = qie.newParameterMap();
endpointParams.put("name", "Sarah Smith");

var evaluatedWithEndpoint = qie.evaluateTemplate(
   endpointTemplate,                   // template
   endpointParams,                     // parameters
   null,                               // escapeFor
   false,                              // isJSON
   "https://example.org/api/patient"   // endpointURL
);


// Example: template with alternateMessages
var altTemplate = "Primary weight={m:weight}, Alternate weight={alt:weight}";
message = qie.createJSONMessage('{"weight":"300lb"}');
var altMessage = qie.parseJSONString('{"weight":"275lb"}');

var evaluatedWithAlternateMessage = qie.evaluateTemplate(
   altTemplate, // template
   null,        // parameters
   null,        // escapeFor
   false,       // isJSON
   null,        // endpointURL
   altMessage   // alternateMessage
);