SPEL expand and do_expand functions

Document created by Gutis Champion on Nov 27, 2015Last modified by Gutis Champion on Feb 24, 2017
Version 2Show Document
  • View in full screen mode

Expand functions can be used to get attribute values at the runtime. It may also be used to evaluate notification templates for the custom objects (for incidents, change and etc there is do_expand function).

 

Some examples if run in cr context:

 

 

 logf(ERROR, "@{ref_num}");
logf(ERROR, expand("@{ref_num}"));
logf(ERROR, "");

Output:
@{ref_num}
143

 

logf(ERROR, "@{type.sym}");
logf(ERROR, expand("@{type.sym}"));
logf(ERROR, "");

Output:
@{type.sym}
Incident

 

 

 logf(ERROR, "$NX_ROOT");
logf(ERROR, expand("$NX_ROOT"));
logf(ERROR, "");

Output:
$NX_ROOT
C:/CA/SDM

 

 logf(ERROR, "${NX_ROOT}");
logf(ERROR, expand("${NX_ROOT}"));
logf(ERROR, "");

Output:
${NX_ROOT}
C:/CA/SDM

 

logf(ERROR, "&{'cr:400080' = cr.persistent_id->ref_num}");
logf(ERROR, expand("&{'cr:400080' = cr.persistent_id->ref_num}"));
logf(ERROR, "");
Output:
{'cr:400080' = cr.persistent_id->ref_num}");
143

Example with notification template

 

object macro;
send_wait(0, top_object(), "call_attr", "macro", "dob_by_persid", 0, "macro:400261"); 
macro = msg[0];
logf(ERROR, macro.msg_tmpl_info.notify_msg_body_html);
logf(ERROR, expand(macro.msg_tmpl_info.notify_msg_body_html));
logf(ERROR, "");

Output:
<p><b> <em><u><br></u></em></b></p><p><b><em><u>Requested by: @{customer.combo_name} status: @{status}</u></em> </b> </p>
>> >>></u></em></b></p>>>>>Requested by: Sauer, Jason  status: AEUR</u></em> </b> </p>

 

Ok it seems that output is corupted, but do_expand function have second parameter, let's try it:

 

object macro;
send_wait(0, top_object(), "call_attr", "macro", "dob_by_persid", 0, "macro:400261"); 
macro = msg[0];
logf(ERROR, macro.msg_tmpl_info.notify_msg_body_html);
logf(ERROR, expand(macro.msg_tmpl_info.notify_msg_body_html,3));
logf(ERROR, "");

Output:
<p><b> <em><u><br></u></em></b></p><p><b><em><u>Requested by: @{customer.combo_name} status: @{status}</u></em> </b> </p>
<p><b> <em><u><br></u></em></b></p><p><b><em><u>Requested by: Sauer, Jason  status: AEUR</u></em> </b> </p>

 

It is also possible to read content of the file from SDM app server by using this command:

string file_content;
file_content = expand("<{" + expand('d:\\folder\\file.csv') + "}");
printf("%s\n", file_content);

 

There is also another function (do_expand) that does similar things and is used by CA, but this function defined only for main objects like cr, chg, cnt and etc.

 

object ticket, macro;
send_wait(0, top_object(), "call_attr", "chg", "dob_by_persid", 0, "chg:400892"); 
ticket = msg[0];
printf("Change: '%s' \n", ticket.chg_ref_num); 
send_wait(0, top_object(), "call_attr", "macro", "dob_by_persid", 0, "macro:400261"); 
macro = msg[0];
printf("incident: '%s' \n", macro.msg_tmpl_info.notify_msg_body_html); 
send_wait(0, ticket, "do_expand",macro.msg_tmpl_info.notify_msg_body_html,3);  
if (!msg_error()) {
   int i;   
   for (i=0;i<msg_length();i++) {   
     printf("msg[%d]: '%s'", i, msg[i]);   
   }
}
else{
   
  printf("Error %s",msg[0]);
}
1 person found this helpful

Attachments

    Outcomes