darius_koohmare
ServiceNow Employee
ServiceNow Employee

It is common for administrators to want to add variable information from a record producer or catalog item into the generated email notification. Conducting this is as simple as being familiar with the syntax and common methods required.

How to add variable data to a notification on the given record (incident, requested item)

You can simply use the syntax ${variables.VARIABLE_NAME} to add the data into a notification.

Note: VARIABLE_NAME is the name of the variable, not the short description or display value. You can see the name of a variable by pressing the cog field in the variables related list and adding the Name column.

There is one common exception to this syntax: when you send a notification for an approval record (sysapproval_approver table), the actual record being approved is stored in a task reference in the sysapproval field. So, to access the variable data you can use ${sysapproval.variables.VARIABLE_NAME}.

Let's take a look at an example using the Development Laptop Catalog Item.

  1. Observe that there is a Variable with the Name hard_drive.
    variable data notification example.png
  2. We can see that there is a requested item record, where a 250GB hard drive was selected.
    variable data notification requested item.png
  3. We can see from the requested item approval notification that the value is accessible using the syntax mentioned.
    variable+data+notification+preview.png

message HTML for approval.png

Request notifications and approvals running on requests will require scripting to access requested item variable data. I recommend using ${mail_script:requested_items_summary_with_options} on the request, or as a baseline example of a mail script that pulls variable data from child items.

Note that Mail scripts are the best approach when you want to make dynamic emails, e.g. one standard email template that is used for all requested items.

template.print("Summary of Requested items:"); 
var gr =new GlideRecord("sc_req_item");
gr
.addQuery("request", current.sysapproval);
gr
.query();
        while(gr.next()){
                  var nicePrice = gr.price.toString();
                  if(nicePrice !=){
                            nicePrice
= parseFloat(nicePrice);
                            nicePrice
= nicePrice.toFixed(2);}
                  template.print(gr.number+":   "+ gr.quantity+" X "+ gr.cat_item.getDisplayValue()+" at $"+ nicePrice +" each");
                  template.print("       Options:");
                  for(key in gr.variables){var v = gr.variables[key];
                            if(v.getGlideObject().getQuestion().getLabel()!=''){
                                      template.space(4);
                                      template.print('         '+   v.getGlideObject().getQuestion().getLabel()+" = "+ v.getDisplayValue());}}}

But when dealing with specialized notifications for items, the syntax above allows you to explicitly call the values you need.

Visit the docs for more information on service catalog variables.

2 Comments