Service Catalogue variables into approval email

AEterni
Mega Guru

Hello Team,

 

I am trying to add a couple of service catalogue variables in an approval email notification.

 

I have reviewed multiple posts on this topic (see below some of them)

https://community.servicenow.com/community?id=community_question&sys_id=04794459db816b04b2102926ca96...

https://www.servicenow.com/community/developer-forum/approval-email-notification-for-a-specific-cata...

https://www.servicenow.com/community/developer-forum/how-to-pass-catalog-item-variables-to-email-not...

https://www.servicenow.com/community/developer-forum/pull-catalog-item-variables-into-email-notifica...

 

However, I was not able to achieve what I want.

 

I found out that there is an out-of-the-box script that should do the trick. The script name is "requested_items_summary_with_options" and this is how it looks like.

 

  template.print("Summary of Requested items:<br />");  
  var item = new GlideRecord("sc_req_item");
  item.addQuery("request", current.sysapproval);
  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 />");  
        }
      }
  }

 

I have replace the "set.setRequestID" with the sys_id of my cat item and injected the script in the notification, but it doesn't work.

 

The reason why it doesn't work is because (I assume) the script is designed to work with the sc_req_item table, but my notification works with the sys_approval table.

 

Any idea how I can add variables from a catalogue item into a notification that works with the sys_approval table?

 

Thank you.

10 REPLIES 10

template.print("Summary of Requested items:<br />");  
  var item = new GlideRecord("sc_req_item");
  item.addQuery("request", current.sysapproval);
  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.toString());
      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 />");  
        }
      }
  }
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi,

 

I am not sure I understand.

 

That's the same script I am currently using that doens't work.

Apologies.

 

I just noticed the difference.

 

set.setRequestID(item.sys_id.toString())

 

I will try.

Yes, that is the only change I made. Apologies, I forget to add comment.

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Much better now.


Last question.

 

How do I pull only one specific variable?

 

Thank you.