Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Copy variables from RITM to Change Request

Henrik Jutterst
Kilo Sage

I've created a UI Script to be able to create a Change Request from a RITM.

This works fine - but is there a way to copy all variables from a RITM and create them on a Change Request?

Depending on Catalog Item, the variables may change/have different name/purpose so I don't want to hard code any variables. Is there a way for this?

1 ACCEPTED SOLUTION

Henrik Jutterst
Kilo Sage

Here's the script I made to do what I was looking for.

 

//copy variables from ritm to change request form
var ritmVar = new GlideRecord('sc_item_option_mtom');
ritmVar.addQuery('request_item', current.getUniqueValue());
ritmVar.addNotNullQuery('sc_item_option.value');
ritmVar.orderBy('sc_item_option.order');
ritmVar.query();

while(ritmVar.next()) {
	
	var chgVar = new GlideRecord('question_answer');
	chgVar.initialize(); 
	
	chgVar.table_name = 'change_request';
	chgVar.table_sys_id = chgSysId;
	chgVar.question = ritmVar.sc_item_option.item_option_new;
	chgVar.order = ritmVar.sc_item_option.order;
	chgVar.value = ritmVar.sc_item_option.value;
	
	chgVar.insert();
}

View solution in original post

9 REPLIES 9

Hmm.. I don't think I understand... This is for creating automatic CHG from a workflow not nothing about getting the variables from one table to another. 

Henrik Jutterst
Kilo Sage

Here's the script I made to do what I was looking for.

 

//copy variables from ritm to change request form
var ritmVar = new GlideRecord('sc_item_option_mtom');
ritmVar.addQuery('request_item', current.getUniqueValue());
ritmVar.addNotNullQuery('sc_item_option.value');
ritmVar.orderBy('sc_item_option.order');
ritmVar.query();

while(ritmVar.next()) {
	
	var chgVar = new GlideRecord('question_answer');
	chgVar.initialize(); 
	
	chgVar.table_name = 'change_request';
	chgVar.table_sys_id = chgSysId;
	chgVar.question = ritmVar.sc_item_option.item_option_new;
	chgVar.order = ritmVar.sc_item_option.order;
	chgVar.value = ritmVar.sc_item_option.value;
	
	chgVar.insert();
}

Hey Henrik,

Did you put this in the UI action?

No I think it was a Business Rule actually.

Thanks for the reply back. I think I need a UI Action to create change but only on a specific request item. So I can hard code it if needed. Not sure if that is possible.