Populate the catalog item Variable label and values in RITM description

Somujit1
Tera Contributor

Hi,

 

Is there a way I can define in the Flow designer, to display the variable label and filled in values on the RITM Description field for the catalog item being requested 

I created a RITM Update record action in the flow to update the Description where it gives me option to select values using data pill and also shows a script option.

 

I have written the below script which return the variable values as comma separated.

However I am not able return the variable label and display it in line break format

------------

var ritmSysId = fd_data.trigger.ritm.sys_id;
var rec = new GlideRecord('sc_req_item');
rec.get(ritmSysId);
var variableValue= rec.variables.getElements();
return variableValue;
---------------
Any suggestions on how to get the Variable label display values and display in sequence
1 ACCEPTED SOLUTION

@Somujit1 

Glad to know.

Yes you can but for that you need to enhance the script and check if the value is not false

something like this

var ritmSysId = fd_data.trigger.ritm.sys_id;


var ritm = new GlideRecord('sc_req_item');
ritm.get(ritmSysId);

var arr = [];
var variables = ritm.variables.getElements();
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
if(label != '' && value != '' && value != 'false'){
arr.push(label + " - " + value);
}
}
return arr.join('\n');

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

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@Somujit1 

update as this

var ritmSysId = fd_data.trigger.ritm.sys_id;


var ritm = new GlideRecord('sc_req_item');
ritm.get(ritmSysId);

var arr = [];
var variables = ritm.variables.getElements(); 
for (var i=0;i<variables.length;i++) { 
	var question = variables[i].getQuestion();
	var label = question.getLabel();
	var value = question.getDisplayValue();
	if(label != '' && value != ''){
		arr.push(label + " - " + value);
	}
}
return 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

@Ankur Bawiskar, Thanks you so much. It works as required.

Is there a way to not display the check box false variables in the RITM description?

 

Regards,

Somujit

@Somujit1 

Glad to know.

Yes you can but for that you need to enhance the script and check if the value is not false

something like this

var ritmSysId = fd_data.trigger.ritm.sys_id;


var ritm = new GlideRecord('sc_req_item');
ritm.get(ritmSysId);

var arr = [];
var variables = ritm.variables.getElements();
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
if(label != '' && value != '' && value != 'false'){
arr.push(label + " - " + value);
}
}
return arr.join('\n');

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

My bad..i was doing it as || value != 'false' instead of &&. 

Thanks again!