how to pass variables in service catalog item to sn_sc.CartJS() in Scripted REST API?

Phalguna
Mega Contributor

Hi,

How to pass the variables of service catalog item to sn_sc.CartJS() .actually I am trying to call the sn_sc.CartJS() API in Scripted REST API.

I have to pass the four variables namely user,location,created by, action type, 

Regards,
Phalguna

 

10 REPLIES 10

sachin_namjoshi
Kilo Patron
Kilo Patron

use below sample code to call cart api with variables

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('e46305bdc0a8010a00645e608031eb0f'); 
cart.setVariable(item,'os','Linux Red Hat');
var rc = cart.placeOrder(); 



Regards,
Sachin

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

this script would help you

try from background

Ensure you give valid variable names and values

var cart = new sn_sc.CartJS();
		var item =
		{
		'sysparm_id': '0d08837237153000158bbfc8bcbe5d02',
		'sysparm_quantity': '1',
		'variables':{
		'user': 'Abel Tuter',
		'location': 'Texas',
		'created_by': 'abel.tuter',
		'action_type': 'hello'
		}};
		var cartDetails = cart.addToCart(item);
		gs.info(cartDetails);
		var checkoutInfo = cart.checkoutCart();
		gs.info(checkoutInfo);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur Thanks for your information,Actually I need to place order.is that checkoutCart  same as place order?

use below code for place order 

 

https://hi.service-now.com/kb_view.do?sysparm_article=KB0714209

 

Regards,

Sachin