
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2020 07:34 AM
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2020 06:55 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2020 07:38 AM
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 />");
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2020 01:00 PM
Thank you! Let me try it out tomorrow and see the result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2020 03:17 AM
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 />");
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2020 08:24 AM
Hello,
I think below example will point you in correct direction.
Mark my ANSWER as CORRECT and HELPFUL if it works.