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);
1 ACCEPTED SOLUTION

Tanushree Maiti
Tera 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:

View solution in original post

15 REPLIES 15

@Sathwik1 

you can use setWorkflow(false) while updating the record so that BR doesn't trigger.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Then I think it wont create requested items also I guess

@Sathwik1 

you can set Requested for using this

CartJS -> setRequestedFor() method

(function runAction(current, event, email, logger, classifier) {
    var subject = email.subject;
    var cart = new sn_sc.CartJS();
    cart.setRequestedFor('userSysId');
    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);

 

55.png

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

carJs will check available for and not avaiable for and alot things I guess, yesteerday I faced any issues with cartJS

@Sathwik1 

you can use setWorkflow(false) while updating the REQ/RITM

did you try that?

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader