Displaying sc_req_item variables on approval notification using sysapproval_approver table

Nicholas Hromya
Mega Guru

Hello everyone,

Now that I got the dedicated approval notification to work, how do I display specific variables from the sc_req_item table on the approval notification?

 

I found where I can get the summary of requested items using the below mail script.  This seems to get all the variables (and works).  But I need to get only five variables and my approvers want to see it in a specific table based format (fun).

 

If I was using a notification using the sc_req_item table, I would use ${variables.<variablename>}, but since I am using the sysapprover_approver table how do get these specific variables?

 

<mail_script>
template.print("Summary of Requested items:\n");
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sysapproval);
gr.query();
while(gr.next()) {
template.print(gr.number + ": " + gr.quantity + " X " + gr.cat_item.getDisplayValue() + " at " + gr.cat_item.price.getDisplayValue() + " each \n");
}

 

TIA

Nick

1 ACCEPTED SOLUTION

shyamkumar VK
Kilo Patron

@Nicholas Hromya ,

 

Can you Try using ${sysapproval.variables.VARIABLE_NAME} to get Variables data from RITM 

Also refer to below link which is similar to your Requirement 

 

https://www.servicenow.com/community/itsm-blog/utilizing-variable-information-in-notifications/ba-p/...

 

Regards,

Shyamkumar 

 

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar

View solution in original post

8 REPLIES 8

Malte_K
Tera Expert

Hello @Nicholas Hromya ,

 

you can use the following syntax if you queried over an sc_req_item record to retrieve variables.

var riGr = new GlideRecord('sc_req_item');
riGr.query();
while(riGr.next()){
  var myVarDisplayValue = riGr.variables.my_var_name.getDisplayValue();
  var myVarTechValue = riGr.variables.my_var_name.toString(); // .getValue(); might not work in scoped apps
}

Nicholas Hromya
Mega Guru

Hello @Malte_K 

Darn, that didn't work. 

 

My sc_req_item variable is "description_body"

 

My mail script (called bulletin_desc_body) is in the body of the notification as 

Description: ${mail_script:bulletin_desc_body}

 

The Description: shows up, but not the variable.

 

I set the above script (bulletin_desc_body) as:

(bolded parts are from when you click "New" within the Notification Email Scripts app from navigator to create email scripts.

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

          // Add your code here

})(current, template, email, email_action, event);
var riGr = new GlideRecord('sc_req_item');
riGr.query();
while(riGr.next()){
  var myVarDisplayValue = riGr.variables.description_body.getDisplayValue();
  var myVarTechValue = riGr.variables.description_body.toString(); // .getValue(); might not work in scoped apps
}
 
Did I do this right?
Thanks
Nick

Hi @Nicholas Hromya ,

 

maybe my example was a bit too generic. I just wanted to show how to get variables if you have a requested item [sc_req_item] GlideRecord.
In the mail script you showed, maybe try the following:

template.print("Summary of Requested items:\n"); 
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sysapproval);
gr.query();
while(gr.next()) {
  var label = gr.variables.description_body.getLabel();
  var description = gr.variables.description_body.getDisplayValue();
  template.print(gr.number + ": " + label + ": " + description + "\n"); // Will create one row for each requested item
  // Format <RITM_NUMBER>: <VARIABLE_LABEL>: <VARIALBE_CONTENT>
}

Neil5
Tera Contributor

Hi Nick, maybe you can start to look at the mail script "requested_items_summary_with_options".