Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Want to show RITM variable in the sysapproval_approver .

NeethuB
Tera Contributor

Want to show RITM variable in the sysapproval_approver.
For that i have created a feild called description (u_description).
I want to show data inside that feild.
eg:
Title:xyx
requestot:ghi 

22 REPLIES 22

 

@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

@NeethuB 

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:

ritm variables in approval comments.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar 
can we put that formatter in ESC portal?

 

Nothing coming in the log