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

shloke04
Kilo Patron

Hi @ian hutchcox 

Please refer the below blog from Amlan which shows this with a clear explanation on how you should do it:

https://community.servicenow.com/community?id=community_blog&sys_id=ee8519acdb00bfc42be0a851ca961921

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke