Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

variable information not populating

suresh kaliappa
Tera Expert

Hi All,

 

My requirement is i need to bring all the variable information that user selected into description field with comma seperated values. Ex. let us assume in a catalog item there is variable A ,  Variable B and variable C. while submitting the request user answered to variable A and Variable B. so in the sc_req_item description field i need to populate those values by seperating commas.

 

I used the following script but it does not works. Sp tell me the way to approach this using business rule. 

 

var escArr = [];
 
    // Resolve List Collector values (Before BR compatible)
    if (current.variables.request_type) {
            escArr.push("Request Type=" + current.variables.request_type);
        }
if (current.variables.instance_name) {
            escArr.push("Request Type=" + current.variables.instance_name);
        }
 
    // ---------- SET DESCRIPTION ----------
    current.description = escArr.join(',');
4 REPLIES 4

Aditya_hublikar
Mega Sage

Hello @suresh kaliappa ,

 

 

Your code is working in my PDI. I attached some screenshot please refer that .I used particular catalog item sys_id in my code , so that BR will run only for that Catalog item.

 

 

adityahubli_0-1768241823889.png

 

adityahubli_1-1768241870765.png

 

adityahubli_2-1768241949889.png

 

 

If this helps you then mark it as helpful and accept as solution.

Regards,

Aditya,

Technical Consultant

 

 

Hello @suresh kaliappa ,

If my response helps you then mark it as helpful and accept as solution.

Regards,

Aditya,

Technical Consultant

yashkamde
Mega Sage

Hello @suresh kaliappa ,
Your solution is correct but quiet straightforward and not dynamic as it consider particular catalog item..
Instead of try this,

var escArr = [];
var grMtom = new GlideRecord('sc_item_option_mtom');
grMtom.addQuery('request_item', current.sys_id);
grMtom.query();

while (grMtom.next()) {
var grOpt = new GlideRecord('sc_item_option');
if (grOpt.get(grMtom.sc_item_option)) {
var label = grOpt.item_option_new.getDisplayValue(); // variable label
var value = grOpt.value; // user’s answer
if (value) {
escArr.push(label + '=' + value);
}
}
}

current.description = escArr.join(', ');

If you find this helpful mark as helpful..

Ankur Bawiskar
Tera Patron

@suresh kaliappa 

it should work

Are you sure BR is configured correctly to trigger?

what debugging did you do from your side?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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