How to create a calculation field?

Phil14
Kilo Explorer

I apologize for the easy question but I'm new at this. 

I'm attempting to modify a total score field (integer) and modify to a calculated field. I want to take 3 separate scores to get a total score. A Score + B Score + C Score = Total Score. 

I'm aware I can click on calculated value tab within the table field, click calculated and add my code but I don't know where to start. 

 

(function calculatedFieldValue(current) {

// Add your code here
return ''; // return the calculated value

})(current);

 

Any assistance would be appreciated. 

 

 

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

I would not use a Calculated Field for this, but create a Business Rule instead. 

 

Calculated fields are calculated every time a row is read, whereas the BR will only run when needed.   You can setup the BR to run when required to update the field.

 

In your business rule, you can use below script

 

current.total_score = current.score_a + current.score_b + current.score_c; // update fields as per your table score fields

 

Regards,

Sachin

View solution in original post

3 REPLIES 3

sachin_namjoshi
Kilo Patron
Kilo Patron

I would not use a Calculated Field for this, but create a Business Rule instead. 

 

Calculated fields are calculated every time a row is read, whereas the BR will only run when needed.   You can setup the BR to run when required to update the field.

 

In your business rule, you can use below script

 

current.total_score = current.score_a + current.score_b + current.score_c; // update fields as per your table score fields

 

Regards,

Sachin

Does it run the calculation even if the row is not included in the list?


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

The SN Nerd
Giga Sage
Giga Sage

Also, you can't report on calculated fields.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022