Build a Maintain Item with a Dynamic Recurring Price - ServiceNow - InterWorks

Build a Maintain Item with a Dynamic Recurring Price – ServiceNow

In this article, we will explain how to update the recurring price field based on a variable that is part of the current catalog item form.

A catalog item can have a recurring price in addition to an initial price.

For example, a subscription to a mobile phone contract could cost $500.00, with a $30.00 monthly recurring price.

The price and the recurring frequency are set on the catalog item record. After the price and frequency are set, the recurring price appears in the catalog, catalog search results, catalog page for the item, shopping cart, and order summary screen.

Maintain Item

Maintain item is an application module that lists a few types of request items like catalog item, record producer, standard change templates, software catalog, hardware catalog, etc. All of these are extended from the base Catalog Item (sc_cat_item) table and used to request fulfillment from your service catalog.

Request and Requested Item (RITM)

When a user orders from the catalog, they add all the items to their cart. Let’s say they are ordering a phone, a PC, and a monitor at the same time. These items are added to the cart. They submit this request containing these three items and a request is generated.

The request is the top-level record for this order, it is the container under which the requested items are included. The ordered items are the requested items.

The catalog tasks are under each requested item and are assigned to fulfillers to complete any work needed for the requestor to get the items they have requested.

Update the recurring price field

We can start with the solution:

  • The maintain item that we created contains 10 variables.
  • Our main focus will be on the Budget Estimate field. This field will be a round number – if a decimal number is entered it will be automatically changed to a round number, also if some string is entered the value will be changed to 0. This functionality is added with an onChange catalog client script.

function onChange() {
   //Type appropriate comment here, and begin script below

                var number = g_form.getValue(‘budget_estimate’);
    var newNumber = ~~parseInt(number);
                 g_form.setValue(‘budget_estimate’, newNumber);
}

  • The value which will be entered into the Budget Estimate field will be calculated with a Budget Calculator which is linked to the Budget Estimate field.

  • When the button Order Now is pressed a Request and RITM are created.
  • To achieve the desired goal for making the Recurring Price to be dynamic, we need to create a business rule that runs on the insert, with after property. To access the variables from the business rule which is on the Catalog Item table we need to access the variables pool with current.variables.variableName.

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

var budEst = current.variables.budget_estimate;
var request = current.request;


                if(current.recurring_price != budEst){
                current.recurring_price = budEst;
                current.price = budEst;
                current.update();
                                }        

                     
var gr = new GlideRecord(‘sc_recurring_rollup’);
                                                                                gr.addQuery(‘request’, request);
                                                                                gr.query();
                                                                                while(gr.next()){

                                                                                                if(gr.recurring_price != budEst){
                                                                                                                gr.recurring_price = budEst;
                                                                                                                gr.update();

                                                                                                }


                                                                                }


})(current, previous);

Benefits and Results

  • The user time is greatly reduced
  • Values for price and recurring price are updated automatically

Conclusion

With this functionality, the users will be able to set the value to the Budget estimate field based on a calculation made with the Budget Calculator which is attached as a link to the Budget Estimate Field. Every RITMs and Requests will have dynamic values.