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

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

That works perfectly. Thanks very much for your help Abhijit

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

notification is on which table?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Requested item

then this should work

No need to query

template.print("<b>Request Type: </b>" + current.cat_item.getDisplayValue() + "<br />");
template.print("<b>Request Variables:</b><br />");

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

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader