Copy variables from RITM to Change Request

Henrik Jutterst
Tera Guru

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
Tera Guru

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

premer
Giga Expert

Hello,

we use the script below to achieve that in a mail notification script. You could adapt this to write the label and display value of your item in your change request.

var gr = new GlideRecord("sc_req_item");
gr.addQuery("number", current.number);
gr.query();
while (gr.next()){
	for(key in gr.variables){
		var v = gr.variables[key];
		if(v.getGlideObject().getQuestion().getLabel()!= '' && v.getDisplayValue()!=''){
				template.print(v.getGlideObject().getQuestion().getLabel()+" = "+v.getDisplayValue()+"<br />");
		}
	}
}

Thank you! Let me try it out tomorrow and see the result.

I would say that the script worked, however it needs to be modified in order to create and fill out variables to the Change Request form. I haven't solved this yet, and since there seems to be some questions regarding this specific question, to copy and create these variables on a new form, I can't really say that this is solved.

 

I created a business rule in order to test this and just dumped the info in a info-message.

var gr = new GlideRecord("sc_req_item");
gr.addQuery("number", current.number);
gr.query();
while (gr.next()){
	for(key in gr.variables){
		var v = gr.variables[key];
		if(v.getGlideObject().getQuestion().getLabel()!= '' && v.getDisplayValue()!=''){
				gs.addInfoMessage(v.getGlideObject().getQuestion().getLabel()+" = "+v.getDisplayValue()+"<br />");
		}
	}
}

 

find_real_file.png

Ct111
Tera Sage

Hello,

I think below example will point you in correct direction.

https://community.servicenow.com/community?id=community_question&sys_id=74ba0f2ddb5cdbc01dcaf3231f96...

 

Mark my ANSWER as CORRECT and HELPFUL if it works.