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

Hi @Sathwik1 ,

 

Check  the role / other condition if mentioned in script in Create and Write ACL on sc_task  once. 

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

@Tanushree Maiti Thank you so much I re-verified it again, it was working perfectly fine.. I need a small modification..

here Requested For value is updating after the request item creation... so due to this.. some existing OOB BR triggering case also along with request..

 

so is there any way we can pass requestedFor  value also at the time of request creation? instead of updating the request again?

 

Also, why in "Email" logs "Target" is not getting filled? generally it used to fill where record get;s created right (It's fine .. just asking)

can you please help @Tanushree Maiti 

Hi @Sathwik1 ;

 

Can you try with following solution as given in this post for " pass requestedFor  value also at the time of request creation? instead of updating the request again"

 

https://www.servicenow.com/community/developer-forum/inbound-email-action-is-setting-the-requested-f....

https://www.servicenow.com/community/itsm-forum/inbound-action/m-p/595379/page/4

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Tried it already but it does not worked, because cart requestedfor is different from requested for on request table.