CA Service Management

 View Only

SPEL expand and do_expand functions 

Nov 27, 2015 03:32 AM

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]);
}

Statistics
0 Favorited
20 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Feb 24, 2017 09:20 AM

Thank You, Daniel i have updated document

Feb 23, 2017 05:49 PM

giedrius, cdtj, Gutis

 

Hi guys,

You can also use the expand function to read the contents of a file to disk.

 

Example.:

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

Nov 27, 2015 07:33 AM

Hope this information will be useful.

Expanding HTML templates works fine as well as with Custom created objects.

To perform this you need to create (or change existing) Object type of Macro and Message template,

this can be done via a lot of methods, but easiest (as I think) is to modify Source code directly in web browser.

 

In complex with HTML Notifications in a context of custom object.  this gives us full control of notification is CA SDM.

Nov 27, 2015 04:41 AM

It is run from the trigger on cr, so it is run on the context of particular cr

Nov 27, 2015 04:16 AM

one more question, in this exaple:

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

 

how did method catch an object to exand from?

Nov 27, 2015 04:07 AM

Thank you cdtj. Second parameter is type of expand do not have any clue what it means

Nov 27, 2015 04:02 AM

Thank you very much, Gutis!

Very nice explanation, I really hated and tried to avoid use of  "expand" until this moment.

 

Did you catched meaning of 2nd param of expand function or have any idea about it?

Related Entries and Links

No Related Resource entered.