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

Anil Lande
Kilo Patron

Hi,

Can you please your screenshot of email notification record (Containing Table and What it will contain part)

Also would need your email script, once we know email configuration then it would be easy to suggest changes.

 

Have you tried adding logs in email notification? Is your email script being called from notification?

 

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,

 

here is the email script. I have replaced the sys_id of my item with xxx.

  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(XXX);
      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 />");  
        }
      }
  }

 

here is the email notification

 

AlessandroEter_0-1665158261413.png

 

here is where I am trying to call the email script.

 

AlessandroEter_1-1665158317209.png

 

AnirudhKumar
Mega Sage
Mega Sage

I'm a little late to the party, but adding my 2 cents here.

Replace line 3 in your main script:

item.addQuery("request", current.sysapproval);

to 

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

Hi @AnirudhKumar,

 

your suggest did something indeed. This is what I get now.

 

AlessandroEter_0-1665212298511.png

Still, this is not what I am trying to achieve.

I need a couple of variables that I defined in the catalogue item.

 

Thank you.