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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Atik

 

Greetings!!

I am not sure, we can add these variables in Task Description and if yes it required a good code to concatenate and show. We can show variable on task OOTB as per my understanding.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

piyushsain
Tera Guru
Tera Guru

Hi,

In the workflow you can create a script activity, in the script you can check the catalog item, and based on the catalog item you can update the Description

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

Atik
Tera Contributor

Hi Piyush,

Can you help me with the code please

Thanks

Atik

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;