sn_sc.CartJS() doesn't work

Theodor
Tera Contributor

Dear community,

 

I'm struggling with my recent problem in that I can't use CartJS() properly for some reasons.

I'm trying to log some requests in a GlideRecord loop by this script:

var today = new GlideDate();
var keepMailbox = new GlideDate();
keepMailbox.addMonths(3);

var gr = new GlideRecord('sys_user');
gr.addQuery('u_expiration_date', today);
gr.query();

while(gr.next()){

var cart = sn_sc.CartJS();    
var request = {
'sysparm_id': '9b0f57e26c4670000fe4d2434fed192f',
'sysparm_quantity': '1',
'variables':{
'hr_end_employee_for_which_user': gr.getUniqueValue(),
'hr_end_employee_user_manager': gr.manager,
'hr_end_employee_user_location': gr.location,
'hr_end_ecid': gr.u_employee_central_id,
'hr_end_employee_is_user_leaving_bunge': 'Yes',
'hr_end_employee_end_date_time': new GlideDate(),
'hr_end_employee_time_sensitive': "No",
'hr_end_employee_notes_data_keep': 'Yes',
'hr_end_employee_keep_data_until': keepMailbox,
'hr_end_employee_notes_data_access_user': gr.manager,
'additional_notes_to_it': "Autotermination due to expiration of the account in AD"
    }
}
var cartDetails = cart.orderNow(request);
gs.info(cartDetails);
}
 
But unfortunately the output is Undefined, Undefined, Undefined. (The loop is working fine, it should be 3 records in that GlideRecord) but I'm not able to log the requests.
Theodor_0-1680518101528.png

 

 
I really don't know what's missing.
 
Thank you in advance for all your support,
Teodor
7 REPLIES 7

Chetan Mahajan
Kilo Sage
Kilo Sage

Hello @Theodor ,

                                  The orderNow() function returns an object that contains information about the order. Check if this object is being returned correctly and if it contains the information you need. You can log the entire object by using gs.info(JSON.stringify(cartDetails));.

 

Kindly mark correct and helpful if applicable. 

Hi Chetan,

 

The result is the same undefined: 

Theodor_0-1680520708189.png

The problem is not only the details are displayed as "Undefined" but the requests are not raised at all !!

 

 

You can try Cart() instead sn_sc.CartJS(). give it try as below in your script 

gs.include('Cart');
    
	var cart = new Cart();
	var req = cart.addItem('65e370ab0a0a3c8101d88e2b883c9efd'); //Cat Item sys_id
	
	cart.setVariable(req , 'hr_end_employee_for_which_user',gr.getUniqueValue());
	cart.setVariable(req , 'hr_end_employee_user_manager', gr.manager);
	cart.setVariable(req , 'hr_end_employee_user_manager', gr.location);
	cart.placeOrder();

Hi Chetan,

 

Unfortunately that was my first option. It worked but Cart can place only one order and can not be used in a loop. It worked to raise only one request and then gets stuck.