How to fetch price of a catalog item which can vary based on variable values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2020 10:59 PM
In my catalog form, there is a list collector where we can select multiple values and each value has a price that will add up to the price of the catalog item. This functionality is working fine. The catalog item price is increasing as per the value selection. But I need to make a variable mandatory and visible if the price exceeds 2500$ before form submission...
Any idea how can I achieve this.
- Labels:
-
Request Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2020 05:00 AM
Hi,
You can get the price value by following code:
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('name','Apple iPhone 6s'); // name of the catalog item
gr.query();
if(gr.next())
{
alert('Price value using GlideRecord is '+gr.price);
}
OR you can use the script include also.
Thanks,
Mohit Kaushik
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2020 08:30 AM
Yeah, this price is okay. But I need the value onchange of price or before form submission. This price through glide record will provide the value updated in the database.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2020 01:19 PM
Hey,
You can use the below code to get the value associated with price in a catalog item:
var price =g_form.getElement('price_span').innerHTML;
var price2 =price.trim().replace('$',''); // this will remove the white spaces and remove the $ sign as well so that you can compare
Now before comparing the values you need to parse this to decimal value and for that you can do it like this.
if(parseFloat(price2)>2500) // this will check your price statement to make your variable available and mandatory.
here price_span is the id of the value of price element in your catalog form. So once you open the catalog form in native UI, you need to select the value of price and do right click to go to inspect. Then from there you can get the Id associated to your catalog's price value. As shown in below screenshot.
Like wise you need to see it in your catalog item form and then it should do the remaining work. Apart from this i don't see there is any other way to get the value.
Please mark this answer correct and helpful if your query is resolved.
Thanks,
Mohit Kaushik
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2020 12:09 AM
I think this approach might work although its throwing javascript error in service portal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2020 01:47 AM
Yes this will not work in Service portal as portal does not support g_form.getElement() method.
I feel there is no other to achieve this functionality apart from modifying the OOB widget. But i would say that is again not a best practice because this widget works for all the catalog items, so your change can affect the functionality for other items as well. You need to do some complex coding i feel to achieve this.
Regards,
Mohit Kaushik
Mohit Kaushik
ServiceNow MVP (2023-2025)
