- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-22-2020 01:57 PM
Hi all,
I have been tasked with triggering the submission of a catalog item when an email is received.
I don't have much of a coding background so I'm sure the problem is somewhere or something to do with my code...
Here is my current inbound action below:
Target table: sc_req_item
Action type: Record Action
Script:
createRequest();
function createRequest() {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('65fcbfee75642400af0e5269def2e168');
cart.setVariable(item, 'sn_req_app', '1');
cart.setVariable(item, 'sn_req_details', 'Sample text');
var rc = cart.placeOrder();
}
A few other points:
- There are no field actions, just the above script
- I have ensured that in my email submission tests, the condition to trigger the inbound action is correct
- The sys_id is pointing to an active test catalog item with only 2 variables both of which are non-mandatory
- Global scope
What I have found is, when the email is received, I get the following mesage in the email log: "Information - Skipping 'inbound_action_name', did not create or update sc_req_item"
In testing I have also noticed that if I place a field action along with the script (for example, Short Description - From email - Subject) it will generate a blank RITM record with no Item attached.
Any help on this would be much appreciated!
Thank you,
Bernard
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-23-2020 05:14 AM
That is all correct. Target table should be Request.
Change your script to look like this:
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('65fcbfee75642400af0e5269def2e168');
cart.setVariable(item, 'sn_req_app', '1');
cart.setVariable(item, 'sn_req_details', 'Sample text');
var rc = cart.placeOrder();
var ritmRec = new GlideRecord("sc_req_item");
ritmRec.addQuery("request", rc.sys_id);
ritmRec.query();
if (ritmRec.next()) {
ritmRec.short_description = email.subject.toString();
ritmRec.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
ritmRec.contact_type = "email";
ritmRec.update();
}
//update target in email table, as it won't be updated as the record was inserted through cart API
if (rc != '') {
var email_rec = new GlideRecord('sys_email');
email_rec.get(sys_email.sys_id);
email_rec.instance = rc.sys_id;
email_rec.target_table = "sc_request";
email_rec.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-21-2020 08:31 AM
I gave that a try thinking that the standard fields (not vars) would be set the same way on the form. Yet when I look at the fields in the REQ & RITM, both are empty. Was thinking that perhaps there might be something clearing them after setting, but can't see anything like that. Going to reach out to our local SN Support Rep.
Thanks for your guidance.
B.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-09-2021 09:17 PM
Hi Michael,
hope you've been well!
I've used this script before I'm sure but something this time is not working. I've narrowed it down to just your script. Here's my script and a screenshot. In my logs the script is not reaching line 8...seems to be hanging up on the "var rc = cart.placeOrder()". I have no user criteria on the catalog item. For now I've stripped out all variables, and none of the variables on the cat item are mandatory. There is an associated workflow for the cat item and it has been published.
See anything I'm missing? thanks!
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('397c59971bc2a0504e73eb12b24bcbef');
gs.log('#### Create RITM from Oracle inbound action is running; line 6');
var rc = cart.placeOrder();
gs.log('#### Create RITM from Oracle inbound action is running; line 8');
var ritmRec = new GlideRecord("sc_req_item");
ritmRec.addQuery("request", rc.sys_id);
ritmRec.query();
if (ritmRec.next()) {
ritmRec.short_description = email.subject.toString();
ritmRec.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
ritmRec.contact_type = "email";
ritmRec.update();
}
//update target in email table, as it won't be updated as the record was inserted through cart API
if (rc != '') {
var email_rec = new GlideRecord('sys_email');
email_rec.get(sys_email.sys_id);
email_rec.instance = rc.sys_id;
email_rec.target_table = "sc_request";
email_rec.upd

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-10-2021 06:06 AM
Strange. Code looks fine and matches doc site: https://docs.servicenow.com/bundle/quebec-application-development/page/script/server-scripting/refer...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-10-2021 06:52 PM
Hi Michael,
yes very strange...I now have the script stripped down to just the bare bones from the docs...and am not able to get it to work in my personal instance. Is there something about the emails I'm sending in? They are being received by the instance, but again it's not reaching the 2nd log entry...it is logging the first log entry, so I know the script is running...which makes me think the "var rc = cart.placeOrder();" isn't working.
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('3c7fee85eb3323008f833c4fea887e45');//test cat item
gs.log('#### Create RITM from Oracle LFG_CMO@lfg.com inbound action is running; line 6');
var rc = cart.placeOrder();
gs.log('#### Create RITM from Oracle LFG_CMO@lfg.com inbound action is running; line 8');
gs.addInfoMessage(rc.number);
})(current, event, email, logger, classifier);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-10-2021 07:30 PM
Found the answer! Thanks to Cody's post:
https://community.servicenow.com/community?id=community_question&sys_id=d0f905041b735c106531ea89bd4bcbb7
Starting with Paris, a catalog item needs to have User Criteria (OOB "Any User" for example) for the cart.placeOrder() to work if you want to allow a Guest user (an unauthenticated user) to use the Cart API to create a catalog request.
I added the "Any User" User Criteria to my catalog item and now it works.