Inbound email action not working ERROR: did not create or update sc_req_item using current
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 04:41 AM
Trying to get the below inbound action to run, but when the email is processed I'm getting the following error:
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
createRequest();
function createRequest() {
var cart = new Cart(); //26ce6d3847759110f42ad0e8736d43b0'); //sys_id of the catalog item
//sets catalog variable to the email's subject
cart.setVariable(item, 'name', email.body.name);
cart.setVariable(item, 'employee_id', email.body.employee_id);
cart.setVariable(item, 'job_title', email.body.job_title);
cart.setVariable(item, 'division', email.body.division);
cart.setVariable(item, 'department', email.body.department);
cart.setVariable(item, 'manager', email.body.manager);
cart.setVariable(item, 'worker_type', email.body.worker_type);
cart.setVariable(item, 'hire_date', email.body.hire_date);
var rc = cart.placeOrder(); //this launches the catalog item, and creates a request object. rc = the request object
updateRITM(rc.sys_id); //call a function immediately to update the ritm. This must be a nested function, otherwise inbound actions get weird.
//also, we're passing the sys_id of the request so we know what RITM to grab.
}
function updateRITM(req) {
var ritm = new GlideRecord('sc_req_item');
ritm.u_name = email.body.name;
ritm.addQuery('request', req); //req is what we passed from the previous function. the sys_id of the request.
ritm.query();
while (ritm.next()) {
var gr = new GlideRecord("sys_user");
gr.addQuery("name", '=', email.body.manager);
gr.query();
if (gr.next()) {
ritm.u_cf_user = gr.sys_id;
var gr1 = new GlideRecord("sc_request");
gr1.addQuery("sys_id", req);
gr1.query();
if (gr1.next()) {
gr1.requested_for = gr.sys_id;
gr1.update();
}
}
ritm.work_notes = email.body_text; //we're still in the inbound action so why not exploit?
//good example of how to exploit email body variables
sys_email.instance = ritm.sys_id;
ritm.update();
}
}
// event.state = "stop_processing"; //stop evaluating inbound actions. This is why I keep this record's order lower than my incident from email rules.
})(current, event, email, logger, classifier);
I've checked the catalog item and made it available for "any user" as suggested in Solved: cart API since Quebec Upgrade - ServiceNow Community
but this still isn't working
Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 05:39 AM
A few quick notes:
- not related to why it does not work, but the Description of Script Include Cart (yes, it is a Script Include) states:
This has been deprecated. Please dont use this Script Include for any usecase. ServiceNow will deactivate the Script Include in coming release.
Please move to https://developer.servicenow.com/dev.do#!/reference/api/quebec/server/sn_sc-namespace/c_CartJSScoped - variable item is not defined, so most likely your script already fails at that point; in any case, since the Catalog Items is not set, creating a Request and Requested Item will not be possible
- variable sys_email is also not defined, you probably mean
email.instance = ritm.sys_id;
not
sys_email.instance = ritm.sys_id;
All in all, the message you mention is not an error that is the cause of a request not being created, it is a result of a request not being created, or updated.