- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2016 07:35 AM
I have a catalog item for storage that needs to update the price based on what kind of storage and how much they are requesting. If they choose one type of storage, it's .40 cents per GB / 12 per month (which when selected it does populate the shopping cart as .40 per month). But, then it asks them how much they want. So, if they say they want 10 GB, it should update the cart to 4.00 per month / 12, but it doesn't because I cannot put pricing implications on a single line of text variable. I can't seem to find a way to do this that doesn't potentially break the shopping cart. Many thanks for your help!
Best,
Chris
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2016 09:49 AM
Hi Chris
I did something similar as you are asking here.
If you make a reference variable, you have the option to check the "Price implications" field.
When you do that, the catalog item will look at the record that the reference variable is pointing at and look for a field named "price" or "u_price". If one is found the value here will be added to the price of the item.
That you do then is you generate a record in a custom table (where you also create a currency field named "price") when catalog item is opened and point a reference variable to this record (remeber to check the price implications box).
Your scripts must then calculate the price based on what the user selects in the different variables and update the record. The price will automatically be reflected in the cart.
See http://wiki.servicenow.com/index.php?title=Service_Catalog_Variable_Pricing#Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2016 09:49 AM
Hi Chris
I did something similar as you are asking here.
If you make a reference variable, you have the option to check the "Price implications" field.
When you do that, the catalog item will look at the record that the reference variable is pointing at and look for a field named "price" or "u_price". If one is found the value here will be added to the price of the item.
That you do then is you generate a record in a custom table (where you also create a currency field named "price") when catalog item is opened and point a reference variable to this record (remeber to check the price implications box).
Your scripts must then calculate the price based on what the user selects in the different variables and update the record. The price will automatically be reflected in the cart.
See http://wiki.servicenow.com/index.php?title=Service_Catalog_Variable_Pricing#Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2016 01:30 PM
I've taken a different approach and very close to solving:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ansval = g_form.getValue('variables.nas_type');
//var ansval2 = g_form.getValue('variables.nas_type_2');
alert (ansval);
//alert (ansval2);
if (!isLoading && newValue != '' && ansval == 'NAS without replication') {
//alert (newValue);
var qty = g_form.getValue ('variables.quantity');
var newprice = ((qty * 0.4) / 12);
alert (newprice);
var price = new GlideRecord ('question_choice');
price.addQuery ('value', 'nas_without');
price.query();
//alert (price.misc);
while (price.next()){
//alert ("hi");
//var newprice2 = ((qty * 0.4) / 12);
//alert (newprice2);
price.rec_misc = newprice;
price.update();
//alert (price.misc);
}
//g_form.setValue('variables.nas_type',ansval);
//var ansval2 = g_form.getValue('variables.nas_type_2')
g_form.setValue('variables.nas_type_2','nas_without');
}
}
But, have another discussion related to setting values. The discussion is: How Do You Set the Value of a Multiple Choice Variable on an onChange Client Script?
My script works and updates the recurring price in the variable, but I need it to then set the value of the variable to the proper answer so it will update the shopping cart.
Any thoughts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2016 06:13 PM
Nope, you were right. It required a custom table. My method was a disaster and I had to re-engineer it with a custom table. Worked great afterwards!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2017 08:44 AM
I seem to have this same type of problem but cannot get the cart price to update dynamically upon onChange of a field on the catalog item form. Ideally I want to set the value of the Reference variable on my form to a unqiue ID which is one of the columns in my pricing table. Prices are added to that table dynamically based upon user input. So once the user inputs to the form, we calculate a price, add the price and a unique identifier to the pricing table, the need to somehow update the cart price with that total cost. How can I achieve this?