- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2022 07:50 AM
I have three currency fields, all on the same table. I need to subtract field B from field A and populate field C with the result.
Essentially A - B = C.
I've gone at this from multiple directions, Calculated value, BU, Client script, but none of the Community suggestions have worked for me. What would be the best way to go about this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2024 06:11 PM
Hi ,
If these fields are on a Table there is no need of creating a client script you can simply perform the calculation on the field by using ServiceNow OOB functionality "Calculated Value" under advanced view where you want to get the result of the calculation.
As per your requirement you can write the code on Calculated Value for the Field "C" as :
var firstValue = currrent.A;
var secondValue = current.B;
var result = parseFloat(firstValue) - parseFloat(secondValue);
return result;
This will return the calculated value to the desired variable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2022 12:35 AM
Rarootes,
Perhaps you could share what you have already done and then the community could give their insights as to why it potentially isn't working?
Thanks,
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 09:42 AM
Okay, so I'm coming back to this.
I am running this in an onChange Client Script. I have two currency fields, and need to subtract one from the other. The original values from a table referenced as an entire section on the form, and the answer is a field native to the form. This is my latest version; I've gone through numerous variations.
Standard function statement followed by:
var budg = g_form.getValue("x_financials.proposed_budget").replace(/,/g, "");
var cost = g_form.getValue("x_financials.total_cost").replace(/,/g, "");
var delta = parseFloat(budg) - parseFloat(cost);
g_form.setValue("x_demand.projected_margin", delta);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2024 06:11 PM
Hi ,
If these fields are on a Table there is no need of creating a client script you can simply perform the calculation on the field by using ServiceNow OOB functionality "Calculated Value" under advanced view where you want to get the result of the calculation.
As per your requirement you can write the code on Calculated Value for the Field "C" as :
var firstValue = currrent.A;
var secondValue = current.B;
var result = parseFloat(firstValue) - parseFloat(secondValue);
return result;
This will return the calculated value to the desired variable.