Trying to create multiple RITM's under a single Req. But having trouble with a duplicate RITM & REQ

Nagendra S
Tera Contributor
var user = this.getParameter('sysparm_user'); //user id from a client script
        var groups = this.getParameter('sysparm_groups'); //List collector - Groups
 
        var catItem = '2bf283eb47422110c5c0fa8bd36d4394';
        var groupString = groups.toString();
        var splitgroups = groupString.split(',');
        for (var i = 0; i < splitgroups.length; i++) {
            var cart1 = new sn_sc.CartJS();
            cart1.empty();
            var singlegroup = {
                'sysparm_id': catItem,
                'sysparm_quantity''1',
                'variables': {
                    'group': splitgroups[i],
                    'user': user,
                }
            };
            var items = cart1.addToCart(singlegroup); //provide the catalog item sys_id and the quantity.
        }
        var checkoutInfo = cart1.checkoutCart();
    },
 
 
The above code works perfectly fine. But the only problem is, we are triggering this script from a onSubmit client script. So,the Cart API is creating 3 RITM's under a single REQ if we have selected 3 groups.
 
But we are also getting a 1 RITM and a different REQ because of the catalog items which will be submitted.
 
Is there any way we can achieve where only 3 RITM's under a REQ is created and avoid the 1 RITM and REQ.
 
Solutions Tried:
1) Record Producer with the same script. But using setAbortAction() is not a good way. So, trying this in catalog item with a client script.
2) Tried adding return false in the client script which is calling the cartApi script include. But the problem here is, users wont know if the Request was submitted/ request was created or not.
 
Thanks in advance. any alternate solution will be appreciated.
1 REPLY 1

Ratnakar7
Mega Sage
Mega Sage

Hi @Nagendra S ,

 

One possible solution is to create a new catalog item that only triggers the script to create multiple RITMs under a single REQ. This catalog item can have a hidden variable that will trigger the script when the form is submitted, without creating any additional RITMs or REQs.

To do this, you can create a new catalog item and add a variable that will be used to trigger the script. This variable should be hidden from the user and set to "true" by the onSubmit client script of the original catalog item.

In the script that creates the multiple RITMs under a single REQ, you can check for the value of this hidden variable and only execute the code if it is set to "true". This will ensure that the script is only triggered when the original catalog item is submitted, and not when the new catalog item is submitted.

 

Thanks,

Ratnakar