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

G Ponsekar
Mega Guru

Hi @VIKAS MISHRA 

 

Use below script:

Assuming current record as RITM record

var str = '';

var variables = current.variables.getElements();
for (var i=0;i<variables.length;i++) {
    var v = variables[i].getQuestion();
    if(v.getLabel() != '' && v.getDisplayValue() != '' && v.type != 14) { //Do not show macros (type 14)
        str += v.getLabel() + ": " + v.getDisplayValue() + "\n";
    }
}

current.description = str;
 
Please mark correct if it is working for you
 
Thanks,
G Ponsekar

Is this a BR

you can use it in Insert BR/Workflows/Flows to accomplish your requirement  @VIKAS MISHRA 

 

Please mark correct if it is working

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