Printings variables in a notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 06:36 AM
var result = new GlideRecord('sc_req_item');
result.addQuery('sys_id', current.sysapproval);
result.query();
if (result.next()) {
var variables = result.variables.getElements();
for (var i = 0; i < variables.length; i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
// labels = ['requester_economic_location', 'requested_for_economic_location', 'manager_location', 'request_for_other_user'];
if ((label != '')) {
template.space(4);
template.print(' ' + label + " = " + value + "<br/>");
}
}
I need to print variables in a notification,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 06:44 AM - edited 12-07-2023 06:45 AM
Hi @Snow-Man,
I had a look into your code and it seems to be fine. Made a little adjustment:
var result = new GlideRecord('sc_req_item');
result.addQuery('sys_id', current.sysapproval);
result.query();
var unwantedVariables = ['requester_economic_location', 'requested_for_economic_location', 'manager_location', 'request_for_other_user'];
if (result.next()) {
var variables = result.variables.getElements();
for (var i = 0; i < variables.length; i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
// Check if the label is in the unwantedVariables list
if (label !== '' && unwantedVariables.indexOf(label) === -1) {
template.space(4);
template.print(' ' + label + " = " + value + "<br/>");
}
}
}
This code creates an array unwantedVariables containing the labels you don't want to print. Inside the loop, it checks if the current label exists in this array using indexOf. If the label is not found in the unwantedVariables list, it will be printed in the notification. If it is found, it will skip printing that variable.
Test it and let me know!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 06:53 AM
Hi, I just tried this. now no variables are getting populated, I feel the if condition is getting false due to which variables are not getting populated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 08:35 AM
Are you writing this code in email script under notifications right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 08:20 AM
As the variables from the RITM are stored in "sc_item_option_mtom"
Can you try below script:
var sc_item_option_mtom = new GlideRecord('sc_item_option_mtom');
sc_item_option_mtom.addQuery("request_item", "sys_id_of_ritm");
sc_item_option_mtom.orderBy("sc_item_option.order");
sc_item_option_mtom.query();
while (sc_item_option_mtom.next()){
var details = GlideappQuestion.getQuestion(sc_item_option_mtom.sc_item_option.item_option_new);
details.setValue(sc_item_option_mtom.sc_item_option.value);
gs.info(details.getLabel() + ": " + details.getDisplayValue());
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.