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

 
0 REPLIES 0