How to create RITM through script ?

Geetha9
Tera Contributor

How to create RITM through script ?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you need to use Cart API

sample script below

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);
}

Regards
Ankur

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

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you need to use Cart API

sample script below

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);
}

Regards
Ankur

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

@Ankur Bawiskar How we can achieve this for multi row variable set? 

@Siddhesh 

you cannot set MRVS using Cart API

what you can do is create RITM from above script and then set the MRVS variable by querying the RITM record using this

ritm.variables.mrvsVariable = 'your json';

Regards
Ankur

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

Harish27
Kilo Guru

Hello,

 

Please check cart api. This is a script include which you can call and set the required variables. You can run this code in server side.

Goto script include and search for cart.

https://community.servicenow.com/community?id=community_question&sys_id=c1a69c91dba75f042be0a851ca96...

Br,

Harish M