how to populate the catalog variable values to RITM description

Pushpa
Mega Expert

Hi Team,

how to populate the current catalog variable values  to RITM description

below variables and variable set fields.

i have 3 variables and one variable set (variable set have 2 fields).

variables 

1. account

2. year

3.quarter 

variable set

4. select location  (location and balance)

how write workflow run script 

 

@Ankur Bawiskar 

 

Regards,

Pushpa

 

1 ACCEPTED SOLUTION

Hi,

account variable should work fine using this

current.variables.account.getDisplayValue();

OR you can query the account table with the sys_id and print the name

then for stockroom showing country do this

var desc = current.variables.description;

if (current.cat_item.name == "Laptop Projection Request") {
    desc += '\nAccount: ' + current.variables.account.getDisplayValue();
    desc += '\nYear: ' + current.variables.year;
    desc += '\nQuarter: ' + current.variables.quarter;

    var parser = JSON.parse(current.variables.add_stockroom_location_and_projection);
    var arr = [];

    for(var i=0;i<parser.length;i++){
        var gr = new GlideRecord("alm_stockroom"); // give here the table name
        gr.addQuery("sys_id", parser[i].stockroom);
        gr.query();
        if (gr.next()) {
            var str = '';
            str = str + "Stockroom: " + gr.location.country + " | " + gr.name + " Projection: " + parser[i].projection;
            arr.push(str);
        }
    }

    desc += '\nAdd Stockroom Location and Projection: ' + arr.join('\n');
    current.description = desc;
    current.update();
}

Regards
Ankur

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

View solution in original post

25 REPLIES 25

Feddy
Kilo Sage

Hi Pushpa, 
You can add the script in the catalog task activity itself, 

click advanced check box and then in script , you can add, (or you can use run script activity as well but you need to use .update();)

current.description=current.variables.<variable backend value> + current.variable_pool.<Variable in the variable set backend value>;


 

Thanks,
Fedrick

Hi feddy,

thanks for your reply.

I used below runscript getting populate the values but getting sys id's (account and stock room getting sys id's how get display values)

please correct below code 

var desc = current.variables.description;


//desc+='\nCost:'+current.cat_item.price.getDisplayValue()+' per month';

if (current.cat_item.name == "Laptop Projection Request") {
    desc += '\nAccount: ' + current.variables.account;
    desc += '\nYear: ' + current.variables.year;
    desc += '\nQuarter: ' + current.variables.quarter;
    desc += '\nAdd Stockroom Location and Projection: ' + current.variables.add_stockroom_location_and_projection;
}


current.description = desc;
current.update();

 

Output:

test
Account: a131f493377f8a00a3ef65e2b3990e91 
Year: 2021
Quarter: Q2
Add Stockroom Location and Projection: [ {
"stockroom" : "ff3aecd71b5eac50e909fee8cd4bcb6d",
"projection" : "45"
}, {
"stockroom" : "913b76041ba6d8904f6f85d8cd4bcb16",
"projection" : "12"
} ]

 

Regards,

Pushpa

use .getDisplayValue();(this will give you the value that is displayed for the field) or if you can use .dot walk to get any specific field which is present in the reference table as well.

Thanks, 
Feddy

How to update getdisplay values in script .

please update code 

and how to remove the brackets in the description