How to create an RITM through script in servicenow

Arka Banerjee1
Tera Contributor

Hi All,

 

I need to create an RITM through run script in workflow in servicenow. Can someone please help with the same. Cart API is going to be deactivated in upcoming release and cartjs api apparently adds to sc_cart_item table. Can someone please help apart from the above

5 REPLIES 5

jaheerhattiwale
Mega Sage
Mega Sage

@Arka Banerjee1 you can directly gliderecord on the requested item table and insert one like below.

 

var ritm = new GlideRecord('sc_req_item');

ritm.initialize();

ritm.short_description = "test";

//set all the required fields

ritm.insert();

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Hi Jaheer,

 

I need to create the ritm for one specific catalog item where I need to populate variables for that specific to that catalog item. Can you help me with the same. Initializing the ritm record would help me set values for sc_req_item table fields and not variables specific to a catalog item

@Arka Banerjee1 Please try below code this should work for you

 

var ritm = new GlideRecord('sc_req_item');

ritm.initialize();

ritm.short_description = "test";

//set all the required fields

 

var itemOption = new GlideRecord("item_option_new");
itemOption.addQuery("cat_item=<YOUR CATALOG ITEM SYS ID HERE>");
itemOption.addQuery("nameISNOTEMPTY");
itemOption.orderBy("order");
itemOption.query();
 
while(itemOption.next()){
ritm.variables[itemOption.name.toString()] = <SET VARIABLE VALUE HERE>;
}

ritm.insert();

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Hi Jaheer,

 

The item_option_new table seems to hold only variables specific to a catalog item. In the ritm that I need to create, there are some variables in variable sets which I need to set as well. Can you suggest me the way to set those variables contained in variable sets..