Requested item variables on notifications

ian hutchcox
Kilo Contributor

Trying to setup notifications from the 'sc_req_item table' when a ticket is logged that will include all the variables from the RITM. I'm using the 'requested_items_summary_with_options' email script as i had this working on notifications from the sc_request table previously.

Ive reverted the script back to out of box, but when i add it to a notification i'm not getting any of the variables from the requested item, its just blank. Ive gone round in circles with this and i cant get it working at all. Any help is greatly appreciated as ive copied and pasted in pretty much every google result i've found in relation to this!.

The email script is as follows:

var item = new GlideRecord("sc_req_item");
scReqItem.addQuery("sys_id", current.sysapproval.toString());
scReqItem.query();
while (item.next()) {
template.print("<b>Request Type: </b>" + item.cat_item.getDisplayValue() + "<br />");
template.print("<b>Request Variables:</b><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() != '' && vs.get(i).getDisplayValue() != '') {
template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "<br />");
}
}
}

1 ACCEPTED SOLUTION

and also your code is not efficient, please try below,

template.print("<b>Request Type: </b>" + current.cat_item.getDisplayValue() + "<br />");
template.print("<b>Request Variables:</b><br />");
var keys = [];
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
if (vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue() != '') {
template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "<br />");
}
}

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

10 REPLIES 10

Abhijit4
Mega Sage

Hi,

There is problem in 2nd and 3rd line, 'item' variable should be used instead of 'scReqItem'

 

Use below code

var item = new GlideRecord("sc_req_item");
item.addQuery("sys_id", current.sysapproval.toString());
item.query();
while (item.next()) {

 

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Thanks for your reply Abhijit.

 

Im kind of new to all this im afraid, in case you didnt guess! I have amended the script as per attached but im still getting nothing through in relation to the ritm variables on the notification. Im sure ive committed a glaring error somewhere but as much as i cut and paste other peoples scripts i cant seem to get this to work.

Ive attached all ive setup so far. If you can see any issues id be very grateful!

 

Apologies, added the incorrect attachment above

Hi,

There is space between item and dot in 2nd and 3rd line, that could be an issue, please remove space and try.

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP