How to auto add all the selected variables along with the value in the RITM description field

VIKAS MISHRA
Tera Contributor

For my particular catalog item, i want to make the changes so that once the RITM is raised then all the selcted variable along with their value should be auto populated in RITM description field as mentioned in the below screenshot.

Please provide the script for the same.

 

VIKASMISHRA_0-1751626396428.png

 

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@VIKAS MISHRA 

you can use Workflow run script or after insert business rule on RITM table

var arr = [];

var variables = current.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 != '' && value != '') {
        arr.push(label + ":" + value);
    }
}
current.description = arr.join('\n');
current.update(); // use this if you are using after insert BR, don't use this when workflow run script is used

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

View solution in original post

7 REPLIES 7

@VIKAS MISHRA 

Hope you are doing good.

Did my reply answer your question?

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

Ashish Parab
Mega Sage

Hello @VIKAS MISHRA

 

You can create After Insert Business rule like below-

Filter Condition : Item is <Select your catalog item>

Script - 

 

(function executeRule(current, previous /*null when async*/) {

    var targetCatalogItemName = 'iPad Pro';// your catalog item

    // Only proceed if this RITM belongs to the specified catalog item
    if (current.cat_item.name == targetCatalogItemName) {

        var ritmDescriptionContent = "--- Submitted Details ---\n"; // Start with a clear header

        current.variables.getElements().forEach(function(variableElement) {
            var variableQuestion = variableElement.getQuestion();
            var varLabel = variableQuestion.getLabel();
            var varValue = variableQuestion.getDisplayValue();

            // Append to the description only if both label and value are present and not just whitespace
            if (varLabel && varValue && varValue.trim() !== '') {
                ritmDescriptionContent += varLabel + ": " + varValue.trim() + "\n";
            }
        });
        // Set the RITM's description field
        current.description = ritmDescriptionContent.trim();
        current.update();
    }
})(current, previous);

 

Output - 

AshishParab_1-1751630006796.png

Let me know if you have any question.

 

Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.

 

Thanks and Regards,

Ashish

 

Brian Sorensen
Giga Guru

If you don't want to use scripts and are more comfortable with Flow Desginer

you can do that there too

 

you would have 

Get Catalog Variables

Update Record - RITM

then add Description field

and in the box format how you have it 

 

BrianSorensen_0-1751630564146.png