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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Pushpa,

update your script as this

var desc = current.variables.description;

if (current.cat_item.name == "Laptop Projection Request") {
	desc += '\nAccount: ' + current.variables.account.getDispayValue();
	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("stockroom table"); // give here the table name
		gr.addQuery("sys_id", parser[i].stockroom);
		gr.query();
		if (gr.next()) {
			var str = '';
			str = str + "Stockroom: " + gr.getDisplayValue() + " 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

Hi Ankur,

Thanks for your reply 

now account getting undefined. 

and same update it into Task (now only populate catalog description value into task description) how to get all ritm description into task 

 

 Regards,

Pushpa

Hi,

account variable line of code was not touched.

you are still using getDisplayValue() on the account variable

Regards
Ankur

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

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.getDisplayValue() + " Projection: " + parser[i].projection;
			arr.push(str);
		}
	}

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

Hi,

is the stockroom related information coming fine?

Regards
Ankur

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