Want to show RITM variable in the sysapproval_approver .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 03:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 06:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 10:39 PM
@Ankur Bawiskar
BR:
Condition:
current.sysapproval.getDisplayValue().startsWith('RITM')
Script:
(function executeRule(current, previous /*null when async*/ ) {
var descriptionText = ''; // Initialize properly to avoid "undefined"
var mtomGR = new GlideRecord('sc_item_option_mtom');
mtomGR.addQuery('request_item', current.sysapproval);
mtomGR.query();
while (mtomGR.next()) {
var varGR = new GlideRecord('sc_item_option');
if (varGR.get(mtomGR.sc_item_option)) {
// Get question text and value
var question = varGR.item_option_new.getDisplayValue() || '';
var value = varGR.getValue('value') || '';
// Optional: Filter out variables you don’t want (e.g., "Requested for")
if (!question.includes("Requested for") && value) {
descriptionText += question + ': ' + value + '\n';
}
}
}
// Set the description field on sysapproval_approver
current.u_description = descriptionText.trim(); // Use .trim() to clean trailing newline
})(current, previous);
NOT WORKING
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 11:00 PM
the BR condition won't work which you gave.
The BR condition and logic I gave worked fine for me and populated the variable summary in comments field.
Please debug it from your side
Use this script
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var arr = [];
var ritm = new GlideRecord('sc_req_item');
ritm.get('sys_id', current.sysapproval);
var variables = ritm.variables.getElements();
for (var i = 0; i < variables.length; i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
if (label != '') {
arr.push(' ' + label + " = " + value);
}
}
current.u_description = 'Variable Summary\n' + arr.join('\n');
})(current, previous);
Output:
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 05:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2025 11:10 PM
Nothing coming in the log