- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 01:40 PM
Hi Everyone,
I have an existing inbound action with the following code:
var grREQ = new GlideRecord('sc_request');
grREQ.requested_for = '165c7f9adbbfa340a9423ebf9d9619a6';
grREQ.short_description = 'Test_8';
grREQ.description = 'Test_8';
//grREQ.parent = current.sys_id;
var reqSysID = grREQ.insert();
var ritm = new GlideRecord('sc_req_item');
ritm.short_description = 'Test_8';
ritm.description = 'Test_8';
ritm.comments = 'Test_8';
ritm.cat_item = '7f8b78b9db19738002b63ebd7c96198b';
ritm.request = reqSysID;
ritm.state = 1;
//Workflow Trigger
var w = new Workflow();
wfSysId = w.getWorkflowFromName("Infosec Approval");
w.startFlow(wfSysId, ritm, ritm.operation());
ritm.insert();
This is working for inbound action, however, we need to change our process and submit or create this catalog item via business rule and when I used this exact script on BR, it's creating REQ, RITM but the workflow is not attaching. Do you have an idea why this happens? Thank you.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2020 08:18 AM
Use below code with cart API to add comments in RITM.
Make sure to pass your catalog item sys_id in cart
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('f8861cbedbed73008d73771c8c961961');
var rc = cart.placeOrder();
var req = new GlideRecord('sc_req_item');
req.addQuery('request',rc.sys_id);
req.query();
while(req.next()){
req.comments = "test comm";
req.update();
}
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 01:42 PM
You need to use cart API from business rule to create service request
https://docs.servicenow.com/bundle/paris-application-development/page/script/server-scripting/reference/r_ServiceCatalogScriptAPI.html
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 11:25 PM
Hi Sachin,
Thanks for your response. But how can I add comments on RITM upon insert if I use cart api?
Regards,
Diane

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2020 08:18 AM
Use below code with cart API to add comments in RITM.
Make sure to pass your catalog item sys_id in cart
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('f8861cbedbed73008d73771c8c961961');
var rc = cart.placeOrder();
var req = new GlideRecord('sc_req_item');
req.addQuery('request',rc.sys_id);
req.query();
while(req.next()){
req.comments = "test comm";
req.update();
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2023 11:52 AM
Hi @sachin_namjoshi / @Ankur Bawiskar ,
I have a similar requirement, could me please help me on this.
Thank you,
Priya.