Order a Order Guide using script

Sai Chetan
Tera Contributor

Hi All,

 

I am trying to create a order guide using script. so i would like to know is there any API we can use to dynamically order a order guide to generate 1 request and multiple ritms inside of it. I have tried SNC.ScriptableOrderGuide API. It is creating multiple RITMs but variables are not getting filled. can anyone guide me with the script on how to do this

3 REPLIES 3

Ratnakar7
Mega Sage
Mega Sage

Hi @Sai Chetan ,

 

Yes, you can use the SNC.ScriptableOrderGuide API to dynamically order an Order Guide and generate one request with multiple RITMs inside it. Here is an example script that you can use as a starting point:

 

var orderGuideAPI = new SNC.ScriptableOrderGuide();
var orderGuide = orderGuideAPI.getOrderBySysID("<Order Guide Sys ID>");

// Set the variables for the Order Guide
orderGuide.variables.<variable_name> = <value>;

// Set the variables for the RITMs
var ritmVariables = [];
ritmVariables.push({name: "<variable_name>", value: <value>});

// Add the items to the cart
var orderCart = orderGuideAPI.createCart(orderGuide, "Requested", ritmVariables);

// Submit the order
orderCart.submit();

 

 

Also refer Running order guides automatically 

 

If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.

 

Thank you!

Ratnakar

Hi @Ratnakar7 , If using my order guide I can order 5 different catalog items, how would i define that in this script also i will not be ordering 5 items it will be conditional say 2 or 3 every time

Hi @Sai Chetan ,

 

You can define the items as an array of objects, where each object represents an item with its associated variables.

Here is an example script that demonstrates this:

var orderGuideAPI = new SNC.ScriptableOrderGuide();
var orderGuide = orderGuideAPI.getOrderBySysID("<Order Guide Sys ID>");

// Define the items to be ordered
var items = [  {name: "<catalog_item_1>", variables: {<variable_name_1>: <value_1>, <variable_name_2>: <value_2>}},  {name: "<catalog_item_2>", variables: {<variable_name_3>: <value_3>, <variable_name_4>: <value_4>}},  {name: "<catalog_item_3>", variables: {<variable_name_5>: <value_5>, <variable_name_6>: <value_6>}}];

// Loop through the items and add them to the cart
var ritmVariables = [];
for (var i = 0; i < items.length; i++) {
  var item = items[i];
  var cartItem = orderGuideAPI.addToCart(orderGuide, item.name, item.variables, ritmVariables);
}

// Submit the order
var orderCart = orderGuideAPI.createCart(orderGuide, "Requested", ritmVariables);
orderCart.submit();

 

In this example, you can define an array of objects called "items" that represents the catalog items to be ordered. Each object has a "name" property that represents the name of the catalog item, and a "variables" property that contains the variables and their values to be set for the item.

You can also make the number of items ordered conditional by using a loop to add items to the cart based on your condition. For example, if you only want to order 2 or 3 items, you can use a loop that iterates through the first 2 or 3 objects in the "items" array.

 

Thanks,

Ratnakar