Issue with cartapi did not create or update sc_request using current

Sam198
Mega Guru

Hi all,

I am having issue with the below inbound action not creating request with using cart api, and the inbound action logs shows this message "did not create or update sc_request using current"

I have confirmed the right catalogue item sysid is used and active, i have added "any user" user criteria as described in couple other post - but still no request. 

 

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
    
    var reqForID;
    
    if(email.body.requestor != undefined){
        //cart.setVariable(item, 'preferred_name', email.body.requestor);
        var user_rf = new GlideRecord("sys_user");
    
        user_rf.addQuery("name", email.body.requestor);
        user_rf.addActiveQuery();
        user_rf.query();
        if(user_rf.next()){
            reqForID = user_rf.getUniqueValue();//if user found, get ID to pass to cart so Requested for will be generated
                gs.log("found: "+reqForID);
        }
    }
    
    if(reqForID){
        
        var cartId = GlideGuid.generate(null);
        //When you create the a cart object by calling the Cart API, the user sys_id you pass in becomes the request's "Opened by" user - NOT Requested For
        var cart = new Cart(cartId, reqForID);
        

        var tempCart = GlideappCart.getCartForRhino(cart.cartName, cart.userID);
        //Now we can set the requested_for user on the temp cart
        tempCart.setRequestedFor(reqForID);
        // Make the tempcart the cart's cart
        cart.cart = tempCart.getGlideRecord();

        var item = cart.addItem('b8224947db683410855d3632f3961945'); //my cat_item
        cart.setVariable(item, 'subject', email.subject);
        cart.setVariable(item, 'body', email.body_text);

        cart.update();

        var rc = cart.placeOrder();

        // Workaround to set target to REQ
        sys_email.instance = rc.sys_id;
        sys_email.target_table = rc.getTableName();
        sys_email.update();

        var reqGr = new GlideRecord('sc_request');
        reqGr.addQuery('sys_id', rc.sys_id);
        reqGr.query();
        if (reqGr.next()) {
            reqGr.short_description = email.subject;
            reqGr.description = email.body_text;
            reqGr.update();
        }
    }

    event.state = "stop_processing"; // to stop processing any further inbound actions

})(current, event, email, logger, classifier);

1 ACCEPTED SOLUTION

Maik Skoddow
Tera Patron
Tera Patron

Hi @Sam 

the used api Cart() is outdated and is recommended to use the new api CartJS(). See https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server/sn_sc-namespace/c_CartJSScop...

Maik

View solution in original post

2 REPLIES 2

Maik Skoddow
Tera Patron
Tera Patron

Hi @Sam 

the used api Cart() is outdated and is recommended to use the new api CartJS(). See https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server/sn_sc-namespace/c_CartJSScop...

Maik

ok Thanks for the info i will change.