Display sum of Two field values in Third field

Ashok Reddy1
Kilo Contributor

Hi,

I've 3 fields where I need the sum of 2 fields to be displayed in 3rd field.

As per the attached image, I want to add the value of 500 and 80 and display the sum value in "Productivity - Test Design" field which is read only field. I know we have to do some scripting under UI Policy for that read only field, but my Code is NOT working. Can someone help me with this? or do we have any other method to do this?

Thank you so much in advance, for helping me.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

is the field read-only from dictionary level?

You cannot do this from UI if the field is read-only; please use before update business rule on your table

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	current.u_field3 = parseInt(current.u_field1) + parseInt(current.u_field2); // give correct field names here

})(current, previous);

Regards
Ankur

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

View solution in original post

4 REPLIES 4

Mohith Devatte
Tera Sage
Tera Sage

Hello,

You can write a after Update BR on your table with below conditions and script 

condition:

Manual test cases designed changes or test design effort changes 

Script

var gr = new GlideRecord('your table name');
gr.addQuery('sys_id',current.sys_id);
gr.query();
if(gr.next())
{
var total = parseInt(gr.manual test cases designed field back end name)+parseInt(gr.test design effort backend name);
gr.setValue(productivity-test design field name,total)
gr.update();
}

Please mark my answer correct if it helps you

Sanjeev Kumar1
Kilo Sage

Hi,

you can use "Function field".

see @ https://docs.servicenow.com/bundle/sandiego-platform-administration/page/build/platform-functions/concept/platform-support-functions.html 

 

Thanks,

Sanjeev kumar

Abhijit4
Mega Sage

Hi Ashok,

You can use function field on "Productivity - Test Design" field as shown below,

find_real_file.png

However, this shows result only when you save the form. If you want result to be shown in UI as soon as value is changed then you will have to write onchange client script on both fields (Manual test cases designed and Number of manual test steps).

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

is the field read-only from dictionary level?

You cannot do this from UI if the field is read-only; please use before update business rule on your table

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	current.u_field3 = parseInt(current.u_field1) + parseInt(current.u_field2); // give correct field names here

})(current, previous);

Regards
Ankur

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