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

@Arka Banerjee1 You can query item_option_new table and query by variable set. then you will get all the fields in that variable set

 

jaheerhattiwale_1-1672392197015.png

 

Then the code will be updated as below

 

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>;
}

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

ritm.insert();
 
Please mark all answers on this question as correct answers
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023