how to add script for calculation

Harshada1
Kilo Contributor

I have 3 choice fields as below

1.  User or Business Value (Drop down values to show: *,**,***,****,*****.  Each star associated with a numerical value: * = 1; ** = 5; *** = 8; **** = 13; ***** = 20)
2. Time Criticality (Drop down values to show: Lowest, Low, Medium, High, Highest.  Each value associated with a numerical value: Lowest = 1; Low = 5; Medium = 8; High = 13; Highest = 20)
3. Risk Reduction / Opportunity Enablement (Drop down values to show: Lowest, Low, Medium, High, Highest.  Each value associated with a numerical value: Lowest = 1; Low = 5; Medium = 8; High = 13; Highest = 20)

I have added above choice with label as left side and value is right side numbers.

A calculation from each field should occur.  The calculation should show the total of "User or Business Value + Time Criticality + Risk Reduction /Opportunity Enablement = CoD (Cost of Delay)" 

how to add this in client script? how to calculate CoD?

below are few screenshots.

4 REPLIES 4

Charles Louis1
Giga Expert

Hi,

You can get the value of your dropdown using g_form.getValue(User or Business Value);

var number1= g_form.getValue('User or Business Value');

var number2= g_form.getValue('Time Criticality');

var number3= g_form.getValue('Risk Reduction /Opportunity Enablement');

var num1= parseInt(number1);

var num2 = parseInt(number2);

var num3 = parseInt(number3);

var Cod=num1+num2+num3;

 

Please Mark this as correct if its helpful.

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please share the script you started with

Regards
Ankur

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

suvro
Mega Sage
Mega Sage

var costOfDelay = parseInt(g_form.getValue('field_name') + parseInt(g_form.getValue('field_name') + parseInt(g_form.getValue('field_name') ;  //You can replace the field name with your fields

Harish KM
Kilo Patron
Kilo Patron

Hi you would need 3 onchange client scripts each on the field to do calculation. Is this catalog form or from table?

if it is table i would prefer Business rule

 

Regards
Harish