We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Duplicate RITMs are created while submitting catalog item using cart- API

Not applicable

I am submitting a catalog item using cart API. but, it's generating multilple duplicate records everytime it execute which i am unable to identify the root case of it.

BR : Async

Table : Astone(u_stone)

Condition: Status changesto 'completed'

insert: true

Script:

(function executeRule(current, previous /*null when async*/ ) {

    try {
        var cart = new sn_sc.CartJS();
        var userid = current.u_user.toString();
        var app_role = 'sys_id of role';
        var item = {
            'sysparm_id': 'sys_id of item', //  //Providing sys_id of the service catalog
            'sysparm_quantity': '1',
            'variables': {
                'requested_for': userid,
                'requested_by': userid,
                'brief_software_description': 'Granting access after learning completion ' + current.u_title,
                'update_access': 'u_modify_access'
                'which_software_requesting': 'sys_id of app',
                'please_select_the_appropriate_role': app_role
            }
        };

        cart.orderNow(item);
        gs.info("Test" + JSON.stringify(cart.orderNow(item)));

    } catch (ex) {
        gs.error('Error triggering Service Catalog item: ' + ex.getMessage());
    }
})(current, previous);
 
also, 'Requested for' on RITM  form is showing different than present 'requested for' on variables of the RITM.
any help on this is really appreciated.
Thanks

 

3 REPLIES 3

brianlan25
Kilo Patron

Not sure if this is the issue with multiple but have you tried running the BR as a before or after rather then async. I don't see anything in the code that would order multiple.

Edit: Also I see in docs that async business rules do not have access to changes to for conditions.

brianlan25
Kilo Patron

For the requested for on the RITM I think you need to add the following after

var cart = new sn_sc.CartJS();

cart.setRequestedFor(current.u_user.toString());

Not applicable

@brianlan25 , thank you for replying. issue is fixed using below script:

 

        var cartid = "cart_" + gs.generateGUID(); // along with gs.generateGUID() we should append "cart_". This can be used as unique id for the Cart.
        var cart = new sn_sc.CartJS(cartid);
            "sysparm_cart_name": cartid // Use "sysparm_cart_name" to set the Cart ID for this cart.
        cart.orderNow(request); // Use "OrderNow" to submit the request.
Thanks,
Abhi