We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Inbound action error: Create Request : did not create or update sc_request using current

Sathwik1
Tera Guru

What is wrong in the below code?

I'm getting below error and shared the code what I used.. also, catalog item is avaialble for all users... I created a new user criteira and added sn_internal and snc_externals roles to that user criteira..

 

Error:: Create Request : did not create or update sc_request using current

 

Code::

(function runAction(current, event, email, logger, classifier) {
var subject = email.subject;
    var cart = new sn_sc.CartJS();
 if (subject.toLowerCase().startsWith("test123")) {

        var catalogItemSysId = '8c456b1d938fba1030c3baba2bba101c';

        cart.addToCart({
            sysparm_id: catalogItemSysId,
            sysparm_quantity: 1,
            variables: {
                additional_information: email.body_html
            }
        });

        cart.checkoutCart();
    }
})(current, event, email, logger, classifier);
3 REPLIES 3

srikanthmadabhu
Tera Contributor

@Sathwik1 

 

The issue was related to the user context under which the inbound email action was running.

 

Even though the catalog item was available to all users and I had created a new user criteria with sn_internal and snc_external roles, the inbound email was not being processed with a user who had proper catalog access.

 

CartJS creates the request based on the current session user. If the email is processed as Guest (or a user without catalog access), the checkout fails and throws:

 

“Create Request: did not create or update sc_request using current”

 

To resolve it:

 

Ensure the inbound email is associated with a valid user.

Verify that the user has access to the catalog and category.

Confirm the catalog item’s Available For / Not Available For criteria include that user.

Once the email was processed under a proper user context with catalog access, cart.checkoutCart() worked as expected.

 

Hope this helps someone facing a similar issue.

 

Thank you.

Tanushree Maiti
Giga Sage

Hi @Sathwik1 

 

Try with this simple code:

 

(function runAction(current, event, email, logger, classifier) {
 
createRequest();
 
function createRequest() {
 if (email.subject.toLowerCase().startsWith("test123")) {
var cart = new Cart();
var item = cart.addItem('8c456b1d938fba1030c3baba2bba101c');
cart.setVariable(item, 'additional_information', email.body_text);
cart.setVariable(item, 'requested_for', <reqFor_sysid>); 
var rc = cart.placeOrder();
 updateRequest(rc.sys_id, reqFor_sysid);
}
 
}
function updateRequest(req, reqfor) {
    var grReq = new GlideRecord('sc_request');
    grReq.addQuery('sys_id', req);
    grReq.query();
    if (grReq.next()) {
        grReq.requested_for = reqfor; 
// Set what other field value you want to set for REQ
        grReq.update();
    }
}
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: