Business Rule to submit catalog item scoped application.

Ben42
Tera Contributor

Hello,

I am using the below script in Business rule to submit catalog item when a ticket in scoped application is updated.

 

script:

var cart = new sn_sc.CartJS();
    //var cart = new gs.generateGUID(null);
    var request = {
        'sysparm_id': 'b128f81f8765c61486a10d4acfcc3652',
        'sysparm_quantity': '1',
        'variables': {
            'first_name': 'Abel',
            'last_name': 'Tuter'
        }
    };
    var cartDetails1 = cart.addToCart(request);
    gs.info(cartDetails1);
    var checkoutInfo = cart.checkoutCart();
    gs.info(checkoutInfo);
    var cartDetails = cart.orderNow(request);
    gs.info('See Details :', cartDetails);
 
But, it is not working... tried using "var cart = new sn_sc.CartJS();" and also tried using "var cart = new gs.generateGUID(null);" still no luck.
 
Any help is much appreciated. 
 
Thanks,
Ben.
5 REPLIES 5

DrewW
Mega Sage
Mega Sage

Looks like from the Docs you can just drop these lines

    var cartDetails1 = cart.addToCart(request);
    gs.info(cartDetails1);
    var checkoutInfo = cart.checkoutCart();
    gs.info(checkoutInfo);
 
Also have you tried this as a background script to see if it works there?  I would also verify you have the sys_id of the Cat Item right and the variable names correct.
 

Ben42
Tera Contributor

Hi Drew,

 

Yes, I have commented out those 4 lines of code and when I run it in the background script I get the below results. but I don't see a RITM or REQ created. 
Script:

var cart = new sn_sc.CartJS();
    //var cart = new gs.generateGUID(null);
    var request = {
        'sysparm_id': 'c364f81f8765c61486a10d4acebb3503',
        'sysparm_quantity': '1',
        'variables': {
            'short_description': 'Hello World',
        }
    };
    var cartDetails = cart.orderNow(request);
    gs.info('See Details :', cartDetails);

Output:

Ben42_0-1713838163053.png


But if I use cart.submitOrder() instead of cart.orderNow(), 13 RITMs are being generated for 1 REQ. which is weird.


Thanks,

Ben.

Ben.

So your output there is the system creating the cart and adding the item to it, but nothing was ordered.

 

What you have to do and the order depends on if you have two step checkout setup or not if memory serves.

 

I think it’s working now! Cart.ordernow(request); is only giving sys id of cart id as per the docs. So, if I use both cart.ordernow(request); and cart.submitOrder(request); it is working.

 

var cart = new sn_sc.CartJS();
    //var cart = new gs.generateGUID(null);
    var request = {
        'sysparm_id': 'b128f81f8765c61486a10d4acfcc3652',
        'sysparm_quantity': '1',
        'variables': {
            'first_name': 'Abel',
            'last_name': 'Tuter'
        }
    };
 cart.orderNow(request);
    var cartDetails = cart.submitOrder(request);
    gs.info('JSON.stringify(cartDetails));
 
Thanks,
Ben.