Add new variable to existing RITM (requested item)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 06:49 AM
Hi,
We need to add some variable to a certain catalog item. by default, the new variables will be added only to newly created requested item.
Does anyone know how can we add the new variables to existing RITM?
Appreciate some help with a script that can do that.
Thank you!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2017 07:43 AM
Hi Eli,
You can do it via fix script.
Sample code would be something like below
var gr = new GlideRecord('sc_req_item');
gr.addQuery('item','sys_id of the catalog item');
gr.query();
while (gr.next()){
gr.variables.newVariableName = 'newVariableValue';
gr.setWorkflow(false);// do not kick of the business rules
gr.autoSysFields(false);
gr.update();
}
Note : This is just a sample code, which you will have to test first. You may have different logic to update variable value may be based on some other fields or variables as well. Also, it is recommanded to do the code testing first on lower environements than prod.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2017 06:16 AM
Hi Deepak,
It seems like the suggested script will set a value to existing variable - is that correct?
What i'm looking for is the following -
I have a catalog item, with 2 variables - Employee name, Employee manager.
till now, we have 30 ticket open for this item.
We were asked to add another variable - employee location.
now, we want that this new variable will be added to the old tickets that were opened.
any suggestion how we can achieve it?
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2017 08:10 AM
Hi Eli,
I just tested and can see that if you add an entry in sc_item_option_mtom table, which is basically relationship between RITM and variable, you will be able to see the new variable in old RITMs, but make sure to also check sc_item_option table and use fix script or background script to update teh data in new variable accordingly.
Regards,
Karthik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2017 01:45 PM
Thank you Karthik.
I played with it and found how to do it - in this script i'm adding all variables of a certain variable set (item_option_new_set) to an existing requested item
var req = new GlideRecord('sc_req_item');
req.addQuery('number','RITM0096847');
req.query();
if (req.next()){
var var_set = new GlideRecord('item_option_new_set');
var_set.addQuery('sys_id',VARIABLE SET SYS ID);
var_set.query();
if (var_set.next()){
var vari = new GlideRecord('item_option_new');
vari.addQuery('variable_set',var_set.sys_id);
vari.query();
while (vari.next()){
gs.print(vari.name);
var option = new GlideRecord('sc_item_option');
option.initialize();
option.item_option_new = vari.sys_id;
option.insert();
var owner = new GlideRecord('sc_item_option_mtom');
owner.initialize();
owner.request_item = req.sys_id;
owner.sc_item_option = option.sys_id;
owner.insert();
}
}
}