RudhraKAM
Tera Guru

I see a lot of posts that are too old to populate the custom variable price ( single-line text ) in a catalog item and add that to the cart total. 

In the below example I want to populate the total amount in the single-line text to add up with the cart value

find_real_file.png

 

find_real_file.png

Below is the solution:

Deactivating the 2 OOB script includes "CatalogPriceCalculator"  and "CatalogRecurringPriceCalculator" so that they will get future updates. 

Make the exact copy of the same script includes for above-mentioned records and add the below code and set the property :" glide.sc.use_custom_pricegenerator " must be set to: true

For reference, I am adding the images of my custom script includes

find_real_file.png

 

find_real_file.png

 

//Same code as above just for copy and paste 
//You can use either price or recurring price based on the requirement

// If this script include is modified to customize price calculation then the following property: glide.sc.use_custom_pricegenerator must be set to: true
var CatalogRecurringPriceCalculator = Class.create();

CatalogRecurringPriceCalculator.prototype = Object.extendsObject(CatalogPriceCalculator, {
    initialize: function( /* GlideRecord */ gr) {
        this.cpc = new SNC.CatalogRecurringPriceCalculator(gr);
        this.cartItem = gr;
    },

    calcPrice: function() {
        var amountVar = this.cartItem.variables['total']; // where 'total' is text field  
        if (amountVar) {
            var num = Number(amountVar);
            return num + this.cpc.calcPrice();
        } else
            return this.cpc.calcPrice();
    }
});





-----------------------------------------------------------------------------

// If this script include is modified to customize price calculation then the following property: glide.sc.use_custom_pricegenerator must be set to: true
var CatalogPriceCalculator = Class.create();

CatalogPriceCalculator.prototype = {
	initialize : function(/* GlideRecord */ gr) { 
this.cpc = new SNC.CatalogPriceCalculator(gr); 
this.cartItem = gr; 
}, 

calcPrice : function() { 

var amountVar = this.cartItem.variables['total']; // where 'total' is text field  
if (amountVar ) { 
var num = Number(amountVar); 
return num + this.cpc.calcPrice(); 
} else { 
return this.cpc.calcPrice(); 
} 
} 
};

Now on the form side create a variable where you want to populate the custom price (ex: total in the below image) , you can use your own formula and calculations and populate the value in the total variable. 

Now create a multiple choice variable with yes or no options and add the 0.01c or any minimum value for one option, in the below example I added 0.01$ for no as a recurring price. You can hide the below variable using UI policy.

find_real_file.png

 

now create an onchange client script on the total variable and set the value for the hidden to yes. this will trigger the script include and add the value in the total variable to the cart.

find_real_file.png

 

 

Just for safe side try creating a on-submit script and return false when No is checked 

 

Comments
Megalithe
Tera Expert

Hello @RudhraKAM ,
This is excellent thank you for documenting this. 🎉🎉🎉🎉

I do have a question regarding the line:

//You can use either price or recurring price based on the requirement

 

I am encountering difficulties passing a recurring value. I have mirrored the values listed in the catalog item pricing options and hoped to pass these values as the cost had in the example, however, I have thus far been unsuccessful.  

Screenshot 2023-08-26 at 2.29.35 PM.png

Thomas Wright
Tera Contributor

For those in organisations that are adverse to any form of customisation, an alternative is to use a set of Select box variables which correspond to each decimal value of a possible price. This avoids the need to change any system property or customise script includes.

See below an example:

ThomasWright_0-1751975912284.png

These variables would all have the "Hidden" checkbox set to true, and the "Visible on Bundles" and "Visible on Summaries" set to false, and their values are set by a client script

Ashu_8871
Tera Contributor

Hello @RudhraKAM 

 

I'm trying to better understand how pricing works for catalog items in our environment.

We store the cost of software in the Software Model table and the cost of entitlements in the Software Entitlement (alm_license_list) table. When we publish a catalog item from a software model, both the Price and Cost fields in the catalog item are populated.

We also use a lookup-type variable set that dynamically updates the price on the Service Portal based on the entitlement selected by the end user. However, this variable set currently adds the entitlement cost to the existing catalog item price, which causes confusion. The requirement is to display only the cost of the entitlement (license).

To address this, we:

  • Commented out the line in ProductCatalogUtils that sets the price field.
  • Set the Price field in the catalog item to 0, so the variable set shows only the entitlement cost (i.e., 0 + entitlement cost = entitlement cost).

However, when the price is updated to 0, a business rule triggers the following line:
GlideappProcessPriceUpdater.updateProcessPrice(current);

This seems to update a flag called ignore_price to true when the price is 0. I want to prevent this behavior so that the ignore_price flag remains false even when the price is set to 0.

The issue is:

  • I can't find the GlideappProcessPriceUpdater script anywhere in my instance or in a PDI.
  • I suspect it's part of a protected or platform-level script include, but I need to understand how to override or disable this behavior.

 

Version history
Last update:
‎07-22-2021 10:02 AM
Updated by: