Catalog Item Price Doubled/Added Instead of Quantity Multiplication

nameisnani
Giga Sage

Hi Team,

 

I'm facing a pricing issue with a catalog item.

 

Catalog Item Price: AUD 11.80

 

Expected:

Quantity 1 = AUD 11.80
Quantity 2 = AUD 23.60
Quantity 3 = AUD 35.40

 

I have a Reference variable (u_quantity_reference) that points to records in a custom table (u_order_guide_quantity).

 

For testing, I updated the quantity record:

Quantity = 2
Price = AUD 23.60

 

But on the catalog item, the displayed price became: 
AUD 35.40

 

which looks like:
11.80 + 23.60 = 35.40

 

Similarly, for Quantity 3:
u_order_guide_quantity Price = AUD 212.00
Catalog Price = AUD 223.80

 

which looks like:
212.00 + 11.80 = 223.80
 
It seems ServiceNow is adding the catalog item's base price (AUD 11.80) to the price from the referenced record.
 

My current calculation in the Script Include is:

 
JavaScript
quantity * getitem.price

 

Why is the catalog item price being added to the reference record price, and what would be the recommended approach to achieve:
 
Total Price = Unit Price × Quantity
 
Below is the on change script
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    g_form.clearValue('u_quantity_reference');

    var quantity = g_form.getValue('u_quantity');
   
        var ga1 = new GlideAjax('OrderGuideUpdateQuantity');
        ga1.addParam('sysparm_name', 'validateQuantity');
        ga1.addParam('sysparm_quantity', quantity);
        ga1.addParam('sysparm_cat_item', g_form.getSysId());
        ga1.getXML(HelloWorldParse1);

    function HelloWorldParse1(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        if (answer != '') {
            g_form.clearValue('u_quantity');
            g_form.showFieldMsg('u_quantity', answer, 'error');
        } else if(quantity>1) {
            var ga = new GlideAjax('OrderGuideUpdateQuantity');
            ga.addParam('sysparm_name', 'checkquantity');
            ga.addParam('sysparm_quantity', quantity);
            ga.addParam('sysparm_cat_item', g_form.getSysId());
            ga.getXML(HelloWorldParse);

        }

        function HelloWorldParse(response) {
            var answer = response.responseXML.documentElement.getAttribute("answer");

            g_form.setValue('u_quantity_reference', answer);


        }
    }


}
 
nameisnani_0-1792581028706.png

 

 

Reference Variable
Variable Name: u_quantity_reference
Type: Reference
Reference Table: u_order_guide_quantity
 
Script Include (Relevant Logic)
checkquantity: function() {

    var getcatitem = this.getParameter('sysparm_cat_item');
    var quantity = this.getParameter('sysparm_quantity');

    var getitem = new GlideRecord('sc_cat_item');
    getitem.get(getcatitem);

    var getquantity = new GlideRecord('u_order_guide_quantity');
    getquantity.addQuery('u_quantity', quantity);
    getquantity.addQuery('u_item_name', getcatitem);
    getquantity.query();

    if (getquantity.next()) {
        return getquantity.sys_id;
    } else {

        var priceupdate = 'AUD;' + (quantity * getitem.price);

        var recinsert = new GlideRecord('u_order_guide_quantity');
        recinsert.initialize();
        recinsert.setValue('u_quantity', quantity);
        recinsert.setValue('u_price', priceupdate);
        recinsert.setValue('u_item_name', getcatitem);

        var sysId = recinsert.insert();

        return sysId;
    }
}
 

Question

Why is the catalog item price (AUD 11.80) being added to the price stored in the referenced u_order_guide_quantity record?

Is this expected behavior for a Reference variable with pricing, and what would be the recommended approach to achieve:

 

Total Price = Unit Price × Quantity

 

can anyone please help me with the fix 

 

where i exactly i need to modidy in script 

 

@Ankur Bawiskar  please hlp me 

nameisnani_1-1792581343492.png

Expected should be : Quantity 2 = AUD 23.60

 

Thanks in advance

 
2 REPLIES 2

Chirag Pathak
Tera Expert

Hi @nameisnani  ,

The base price is already added by the catalog, so calculate only the incremental price difference.

Try something like this in your script include for the function checkQuantity

var priceupdate = 'AUD;' + ((quantity - 1) * getitem.price);



BhavaniYamsani
Tera Expert

Hi @nameisnani ,

The likely root cause is the Price implications setting on the reference variable u_quantity_reference. When enabled, ServiceNow adds the referenced record's price to the catalog item's base price, potentially causing double counting.

For example, if the base price is AUD 11.80 and the referenced record contributes AUD 23.60, the total becomes AUD 35.40 instead of AUD 23.60.

Solution:

  1. Open the catalog item and navigate to its Variables related list.

  2. Open u_quantity_reference and check Price implications.

If you disable Price implications as referenced screenshot, the referenced record's price will no longer automatically contribute to the catalog item's total through that variable. However, the existing script may not work as intended if it relies on that price contribution.

If you want to retain Price implications, and the base price is already included, adjust the calculation to return only the incremental price as @Chirag Pathak says

var priceupdate = 'AUD;' + ((quantity - 1) * getitem.price);

Test both approaches with different quantities to confirm the final price. The incremental calculation is appropriate only if the base price is already included in the total.

If this answer helps, please mark it as helpful. 

Thankyou
Yamsani Bhavani
ServiceNow Developer - SecOps, GRC, Custom Applications, Now Assist