How can we display the request form variables on catalog task description?

Atik
Tera Contributor

Hi All,

I am working on workflows, As i have a requirement that i need to update the catalog task description with the catalog item form variables(Requested Item) values,

But my concern is, there are 8 catalog items and we are using the same workflow for all of them and for 8 catalog items there are different variables.

So how can achieve this? is it feasible in ServiceNow? or i need to create different workflows for all the 8 catalog items?

Please help

 

Thanks and Regards,

Atik 

2 ACCEPTED SOLUTIONS

We have been using the following script for many years:

 

var str = '';

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

current.description = str;

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@Atik 

let same workflow be used for different catalog items.

you can use this script to populate the variable values in catalog task description inside the Catalog task activity Advanced script

You need to enhance it to handle MRVS if you are using it in any of your catalog items

var arr = [];

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) {
		var str = v.getLabel() + ": " + v.getDisplayValue();
		arr.push(str);
	}
}

task.description = arr.join('\n');

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

Atik
Tera Contributor

Thank you so much it exactly meet my requirement

Utpal Dutta
Tera Guru

Hi Atik,

If you want to update the description only for a specific catalog item then you should just put that condition into an if condition stating that if item is this then only update the description. 

On RITM, Item field contains the value of Catalog item. So you just need to compare item field with sys_id of the catalog item that you want to update for.

 

I hope my answer helps. If it does please mark it correct.

 

Thanks,

Utpal

Ankur Bawiskar
Tera Patron
Tera Patron

@Atik 

let same workflow be used for different catalog items.

you can use this script to populate the variable values in catalog task description inside the Catalog task activity Advanced script

You need to enhance it to handle MRVS if you are using it in any of your catalog items

var arr = [];

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) {
		var str = v.getLabel() + ": " + v.getDisplayValue();
		arr.push(str);
	}
}

task.description = arr.join('\n');

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