How to create an RITM through script in servicenow
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2022 08:16 AM
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2022 01:25 AM
@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
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
ServiceNow Community Rising Star, Class of 2023