service catalog total price calculation from multi set variables

Srini Panduri
Kilo Expert

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

 

 

 

 

 

      

 

  

 

 

1 ACCEPTED SOLUTION

I doubt you can set the price dynamically based on MRVS

You can check this link

Using variables for price setup

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@Srini Panduri 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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

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

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