inbound action not creating request / "did not create or update sc_req_item"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2017 11:47 AM
I created an inbound action to create a request/RITM/Task. The condition is met and the rule fires but fails with message "did not create or update sc_req_item". The target table is sc_req_item, action type is Record Action. The "When to Run" condition is being met and triggering the rule.
This is my script:
createRequest();
function createRequest() {
//Get Requested For
var usr = new GlideRecord('sys_id');
usr.addQuery('user_name',email.body.username.toString());
usr.addActiveQuery();
usr.query();
if(usr.next() && email.body.comments.toString())
{
var grRequest = new GlideRecord ("sc_req_item");
grRequest.initialize();
grRequest.requested_for = usr.sys_id;
grRequest.short_description = email.body.url.toString();
grRequest.description = "received from: " + email.origemail + "\n\n" + email.body_text;
var requestSysId = grRequest.insert();
//Create Request Item
current.requested_for = usr.sys_id;
current.short_description = email.body.url.toString();
current.description = "received from: " + email.origemail + "\n\n" + email.body_text;
current.cat_item = '9ad82be3db448740c03a77e9af96196a';
current.parent = requestSysId;
current.request = requestSysId;
current.insert();
}
}
When I look at the email log from the failed request creation, it shows as: Skipping {My Rule Name}, did not create or update sc_req_item
Does anyone have any idea what I might need to change so this works correctly?
Any assistance is greatly appreciated
Thanks,
Heidi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2017 11:51 AM
Looks like you are trying to create two sc_req_item records, on is grRequest, which points to that table (sc_req_item), and the other is current, also pointed to that table. Were you trying to create the request (sc_request) and it's subsequent requested items?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2017 12:28 PM
Yes. I am trying to create the Request, the RITM and the Task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2017 12:41 PM
It might be better to use the Cart API for something like this. If you try creating all of those records manually, it can get quite hairy- WorkFlow, Business Rules, REQ, RITM, TASK are all involved.
var ourUser = gs.getUser();
var catItem = 'sys_id.of.item';
gs.include('Cart');
//create a cart
var catCart = new Cart();
var item = catCart.addItem(catItem, 1);
catCart.setVariable(item, 'requested_for', ourUser);
catCart.setVariable(item, 'comments', email.body);
var placeOrder = catCart.placeOrder();
Something to that effect. The table would be 'sc_cart' in the inbound action. You can then take the 'placeOrder' object (i.e placeOrder.getValue('sys_id')) and use that to query against the REQ and RITM tables if you need to modify any of the other request values.
This might help:
Service Catalog Script API - ServiceNow Wiki
Hope that helps!
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2017 01:12 PM
Hello Heidi.
Please have a look at Examples 2 and 3 here:
Examples of incoming emails & matching inbound actions without a "real" update