Creation of RITM from UI Action

Balaraju K B
Tera Expert

Hi Everyone,

 

I have a requirement to create an RITM by submitting the catalog item from UI Action script.

Instance Version : Tokyo

Note : UI Action is on a table which is Custom scoped table and the Catalog item which needs to be created RITM is Global one.

 

Can anyone help me with the script here?

@Ankur Bawiskar Any idea on this Ankur?

 

Thanks in Advance,

Balaraju K B

1 ACCEPTED SOLUTION

@Balaraju K B 

try this and it works in global + scope

try{
	var cart = new sn_sc.CartJS();
	var item =
		{
			'sysparm_id': '0336c34407d0d010540bf2508c1ed096',
			'sysparm_quantity': '1',
			'variables':{
				'user': '7282abf03710200044e0bfc8bcbe5d03',
				'asset': '00a96c0d3790200044e0bfc8bcbe5dc3',
				'multiple_choice': 'Phoenix',
			}};
	var cartDetails = cart.addToCart(item);
	var checkoutInfo = cart.checkoutCart();
	gs.info('Order details' + JSON.stringify(checkoutInfo));
}
catch(ex){
	gs.info('Exception'+ex);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

15 REPLIES 15

Ankur Bawiskar
Tera Patron
Tera Patron

@Balaraju K B 

you can use cart api for this

something like this

try{

	var cartId = GlideGuid.generate(null);
	var cart = new Cart(cartId);
	//add your requested item to the cart by sys_id of the catalog item
	var item = cart.addItem('0336c34407d0d010540bf2508c1ed096', 1);

	//fill in the variables on the request item form
	cart.setVariable(item, "asset", "00a96c0d3790200044e0bfc8bcbe5dc3");
	cart.setVariable(item, "multiple_choice", "Phoenix");
	var rc = cart.placeOrder();
	gs.info(rc.number);

}
catch(ex){
	gs.info(ex);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar  Thanks for your reply,

 

Does UI Action requires Client checkbox to be checked?

@Balaraju K B 

nope

the UI action should be server side.

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

@Ankur Bawiskar Tried adding the script in the UI Action but nothing is happening on Clicking of the button. Please refer the below screenshot :Create RITM Button.PNG

Note : The table which i wrote the UI Action is Scoped application and RITM table is Global is there any Cross Scope access issue?