Add new variable to existing RITM (requested item)

Eli Guttman
Tera Guru

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!

10 REPLIES 10

kevinanderson
Giga Guru

The above did not work for me.  I had to create the item option and the mtom relationship before I could add the variable to the ritm:

 

var gr = new GlideRecord('sc_req_item');
gr.addQuery('number', '<MY TARGET RITM TO UPDATE WITH NEW VARIABLE>');
gr.query()

if(gr.next()){
  gs.print(gr.number+' '+gr.cat_item.name)
  
  // create option
  var gr2 = new GlideRecord('sc_item_option');
  gr2.initialize();
  gr2.item_option_new = '<sys_id if variable as found in item_option_new>'; 
  gr2.value = '<desired variable value>';
  var id = gr2.insert();


  // create mtom relationship
  gr2 = new GlideRecord('sc_item_option_mtom');
  gr2.initialize();
  gr2.request_item = gr.sys_id;
  gr2.request_item.cat_item = gr.cat_item;
  gr2.sc_item_option = id;
  gr2.insert();


  gr.variables.<variable name as defined in item_option_new record> = '<desired variable value>';

  gr.update();
  

}

This worked perfectly. Thanks!

Kevin just wanted to thank you so much for this - VERY HELPFUL.  Thank you.  IT WORKED.

Thanks @kevinanderson it worked perfectly.

This is the script to update one RITM.

So if  I need to update existing RITMS in bulk is that possible?

Thanks,

Priya

 

@kevinanderson 

 Can you please help to get these variables to catalog task level as well?