Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Email script to print RITM variables (from an Order Guide) into an email notification.

Brun
Mega Expert

Hello Experts,

I have an Order Guide that will include Item when submitted. Within the requested item's workflow, I'm triggering an event to send off a notification with a summary of the RITM variables. I've tried a few email scripts, but they aren't returning any values. 

Can anyone help with this?

 

Email Script:

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


    // Add your code here

 template.print("Summary of Requested items:<br />");  
  var item = new GlideRecord("sc_req_item");
  item.addQuery("request", current.sys_id);
  item.query();
  while(item.next()) {
      template.print(item.number + ":  " + item.quantity + " X " + item.cat_item.getDisplayValue() + " at " + item.cat_item.price.getDisplayValue() + " each <br />");
      template.print("    Options:<br />");
      var keys = [];
      var set = new GlideappVariablePoolQuestionSet();	
      set.setRequestID(item.sys_id);
      set.load();
      var vs = set.getFlatQuestions();
      for (var i=0; i < vs.size(); i++) {
        if(vs.get(i).getLabel() != '') {
           template.space(4);
           template.print('     ' +  vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "<br />");  
        }
      }
  }



 })(current, template, email, email_action, event);

 

Thank you,

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

notification is running on sc_req_item table ? if yes then please update addQuery() line

 

item.addQuery("sys_id", current.sys_id);

View solution in original post

2 REPLIES 2

Harsh Vardhan
Giga Patron

notification is running on sc_req_item table ? if yes then please update addQuery() line

 

item.addQuery("sys_id", current.sys_id);

Thank you, thank you! That was the issue. Appreciate the help!