- 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
ā01-22-2020 04:11 PM
Hi Bernard,
The script seems to be fine, just try this to validate it properly:
- Run your script in "Script - Background" - Validate if the REQ/RITM are created properly.
- Remove the table name from your Inbound Action - The script is creating the REQ/RITM automatically.
Workaround: If it is not working from an Inbound Action, try it by using a Business Rule. The inbound action will insert the record, this will help you to trigger your business rule.
Hope this helps,
Pedro

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-22-2020 05:12 PM
The inbound action should be on the request table.
The type should be New, not Record Action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-22-2020 06:14 PM

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