The CreatorCon Call for Content is officially open! Get started here.

Changing Cart Quantity based on Order Guide Variable Using a Business Rule

tstocking
Tera Guru

Changing Cart Quantity based on Order Guide Variable Value Using a Business Rule

I couldn't find the answer to a scenario we came up with so I figured out a solution and thought I would share it for those looking to do something similar.   Side note, I've only been working with ServiceNow for a few months so there may be a better or more elegant approach but we found this method to work nicely.

Scenario:   You want to create an Order Guide that has one or more variables associated with it.   From here, you want to create one or more rule bases to include items from your Service Catalog.   However, based on the variables selected in the Order Guide, you want to adjust the quantity of a specific Catalog Item to a value greater than the default of "1".   While the option exists for a user to change the quantity in the shopping cart themselves, it is a better user experience to pre-configure their cart if the Order Guide is for a bundle that is in itself pre-configured.

For example:   You have a Desktop Computer Setup Bundle that could have either a (2) Monitor setup or a (4) monitor setup depending on the Department that the user works in.

  1. Service Catalog | Order Guide | New
  2. Configure the Order Guide (enter a name, select a catalog, select a category, description, etc)
  3. Create a variable on the Order Guide (in my scenario, I ask a Yes or No question as to whether the user works in a certain department, e.g. Investment Office User)
  4. Enable the Cascade Variable Option within the Order Guide
  5. Create a Rule Base to include an item from the Service Catalog.   In my scenario, I am including a 22" Monitor.
  6. Save the Order Guide
  7. Edit the Service Catalog Item referenced in Step 5 to include the same variable from Step 3.   Since I didn't want to show people this when they ordered a monitor directly, I created a new UI Policy to hide this variable always.   This is not required but just the way I set it up.
  8. Create a new Business Rule
    1. Select Table "Item [sc_cart_item]"
    2. Select When "Before"
    3. Select "Update Checkbox"
    4. Select "Advanced"
    5. Filter it for "Item | Is | 22" Monitor"
    6. Use the following code under the Advanced Tab:

(function executeRule(current, previous /*null when async*/) {

var investmentUser = current.variables.investment_user;

if (investmentUser == 'no') {

  current.quantity.setValue('2');   // here we set the quantity of Monitors to a value of 2 because thats the standard user setup

}

  else {

  current.quantity.setValue('4');   // here we set the quantity of Monitors to a value of 4 because thats what an Investment User gets

  }

})(current, previous);

So when someone executes an order guide, the cart will either have 2 monitors of the same item or 4 monitors of the same item added based on which department they work in.

find_real_file.png

7 REPLIES 7

Bharath Padaki
ServiceNow Employee
ServiceNow Employee

Hi Todd,



This is something we have included as part of the product starting Helsinki. This configuration should be available under the Rule Base settings


Hi Bharath,

how is this configuration in the rule base achieved?  I'm on a Kingston instance.  

I see the "Quantity" variable on the rule base record...but how is that triggered to add the quantity of an item to the cart?  thanks 

Actually nevermind Bharath, 

found it

https://docs.servicenow.com/bundle/kingston-it-service-management/page/product/service-catalog-management/task/t_CreateARule.html

 

thanks!

🙂