- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2021 02:34 PM
Hello All
With one of requirement I am building service catalog. total price needs to calculate from muti variable set fields.
I am seeing the issue for below call
alert(JSON.parse(g_form.getValue('multi_variable_set_name'));
I am seeing null all the time , do i need add any property to get that mvs values in json format to calculate the price.
Once total calculated , How to reset the catalog item price as below is not working
g_form.setValue('price',"total_cost");
Thank you in advance.
Regards
Srini
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2021 06:12 AM
I doubt you can set the price dynamically based on MRVS
You can check this link
Using variables for price setup
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2021 05:35 AM
So are you saying based on variable within MRVS you need to set the price variable present on catalog form?
You need to get the JSON string from MRVS; iterate the json; add the price and then set the value
Example script below
var str = g_form.getValue('mrvsVariableSetName'); // give here the mrvs variable set name
var total = 0;
var parser = JSON.parse(str);
for(var i=0;i<parser.length;i++)
total = total + parseInt(parser[i].price); // give here the percentage variable name
g_form.setValue('price', total);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2021 08:16 AM
Thanks Ankur.
I am using same logic from another post from you. The issue is even after adding MRVS rows in catalog item , I am getting null value from below call.
var parser = JSON.parse(str);
Also I unable change price even i hardcoded like below.
var total = 500.00;
g_form.setValue('price', total);
I am seeing below message on catalog client script , do i need change any property.
New client-scripts are run in strict mode, with direct DOM access disabled. Access to jQuery, prototype and the window object are likewise disabled. To disable this on a per-script basis, configure this form and add the "Isolate script" field. To disable this feature for all new globally-scoped client-side scripts set the system property "glide.script.block.client.globals" to false.
Regards
Srini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2021 08:33 AM
After adding "Isolate script" field to client script , now I am getting JSON string to calculate total_price.
I am not able to set price from calculation
g_form.setValue('price', total);
Regards
Srini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2021 01:40 PM
After adding "Isolate script" field to client script , now I am getting JSON string to calculate total_price.
I am not able to set price from calculation using below call.
g_form.setValue('price', total);
Is there any other way to reset catalog price.
Regards
Srini