How to calculate two choice field values and populate in another field.

venkat Y
Tera Contributor

 Each of the field values need to have the following points assigned to each value for the calculation

a. Capability
1. Low = 1 point
2. Medium = 2 points
3. High = 3 points
b. Associates
1. < =100 = 1 Point
2. 101 to 1,000 = 2 Points
3. 1,001 to 10,000 = 3 Points
4. 10,001 to 50,000 = 4 Points

calculation should sum up the associated points for each value selected in capabilityAssociates fields

The "Effort " field needs to be a calculated field based on two other fields which are mentioned, and populate these choice depend on calculation

  1. a.  Not Prioritized - 0 points
  2. b.  Low - less than or equal to 5 points
  3. c.  Medium - greater than 5 points but less than or equal to 9 points
  4. d.  High - 10 or higher points

 

1 ACCEPTED SOLUTION

AnubhavRitolia
Mega Sage
Mega Sage

Hi @venkat Y 

 

You can create Choices of field as below:

 

AnubhavRitolia_0-1668271625946.png

AnubhavRitolia_1-1668271662363.png

 

Then you can write below code in your 2 onChange Client Script for Capabilities and Associates field:

 

var cap = parseInt(g_form.getValue("u_capability");
var ass = parseInt(g_form.getValue("u_associates");
var eff = cap+ass;

if(eff==0)
{
g_form.setValue('u_effort','Not Prioritized');  // value of choice 'Not Prioritized'
} else if (eff<=5) {
g_form.setValue('u_effort','Low');  // value of choice 'Low'
} else if (eff>5 && eff<=9) {
g_form.setValue('u_effort','Medium');  // value of choice 'Medium'
} else if (eff>10) {
g_form.setValue('u_effort','High');  // value of choice 'High'
}

 

 

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

View solution in original post

7 REPLIES 7

AnubhavRitolia
Mega Sage
Mega Sage

Hi @venkat Y 

 

You can create Choices of field as below:

 

AnubhavRitolia_0-1668271625946.png

AnubhavRitolia_1-1668271662363.png

 

Then you can write below code in your 2 onChange Client Script for Capabilities and Associates field:

 

var cap = parseInt(g_form.getValue("u_capability");
var ass = parseInt(g_form.getValue("u_associates");
var eff = cap+ass;

if(eff==0)
{
g_form.setValue('u_effort','Not Prioritized');  // value of choice 'Not Prioritized'
} else if (eff<=5) {
g_form.setValue('u_effort','Low');  // value of choice 'Low'
} else if (eff>5 && eff<=9) {
g_form.setValue('u_effort','Medium');  // value of choice 'Medium'
} else if (eff>10) {
g_form.setValue('u_effort','High');  // value of choice 'High'
}

 

 

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

@AnubhavRitolia  woww nice Anubhav, Thanks for the code

@venkat Y 

 

Most welcome.

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023