Pull catalog item variables into email notification for TASK

gnunez
Kilo Guru

Hello all,

We have a catalog item that does not have a Description field when a user is completing the request so when the email notification 'Request Opened on your Behalf" is triggered, the description in the email body is blank. The same goes for when the email notification for the associated task is triggered since the description field is blank.

We would like to see if there is a way to add the catalog item variables (fields from the original request)   onto the email notification so the user receives useful information.

I was able to achieve this by adding the variable names onto the message html for the email notification, but since this is something we want to accomplish across multiple catalog items I would like to see if there is a generic script I can use.

Below is what I currently tested:

find_real_file.png

Thanks in advance!

Grace

1 ACCEPTED SOLUTION

YenGar
Mega Sage

Hi Grace,



There's an OOB script called 'requested_items_summary_with_options' in the Notification Email Scripts:



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


              }


          }


  }



Set your item sys_id in the set.SetRequestID line. This will fetch the variable names with their answer, you can modify it as needed.


Once you've modified it, you can add this email script to your notification body by adding ${mail_script:requested_items_summary_with_options} to it.



Hope this helps!



Yeny


View solution in original post

9 REPLIES 9

Hi Grace,



Try putting the sys_id in single quotes. For example: set.setRequestID('4fcf51adfc09240c360b3318110c7f5');. That should work.



Yeny


Thank you Yeny this fixed my issue!


Hi , 

 

by item.sys_id you mean the sys_id of the catalog item? 

 

find_real_file.png

darius_koohmare
ServiceNow Employee
ServiceNow Employee

Since there's a one to many relationship between a request and numerous catalog items, the script is necessary. Yeny provided it, but here is some more info on the topic: Utilizing variable information in notifications


Thank you Darius, both you and Yeny were very helpful!