- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi,
I have a requirement where on the intake form there are 2 fields, total cost and % of funding. There is a 3rd field total funding cost which populates the percentage value of above fields. For ex, if % of funding-60, total cost- 100 then total funding cost should show 60.
How this can be achieved?
Thanks in advance!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
You could do this with both Business Rules and Client scripts. Possibly both depending on your use case.
Something like the below Business Rule could work for you.
// Table: your intake table (e.g., x_myapp_intake)
// When: Before Insert, Before Update
(function executeRule(current, previous /*null when async*/) {
var cost = parseFloat(current.total_cost || 0);
var pct = parseFloat(current.funding_percent || 0);
var funding = (cost * pct) / 100;
// If the field is currency/decimal, set to a number
current.total_funding_cost = funding.toFixed( 2 );
})();
If you want to display within a Catalog item you'll need a Catalog Client Script, something like this should work...
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) return;
// Recalculate whenever either variable changes
function recalc() {
var cost = parseFloat(g_form.getValue('total_cost')) || 0; // currency/number variable name
var pct = parseFloat(g_form.getValue('funding_percent')) || 0; // % variable name (0–100)
var funding = (cost * pct) / 100;
g_form.setValue('total_funding_cost', funding.toFixed( 2 )); // currency variable name
}
recalc();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
You can create an OnChange client script on both total cost and % funding fields, get their numeric values (use g_form.getDecimalValue(...) if they are currency/number fields), compute totalCost * (percentFunding/100), and use g_form.setValue(...) to populate total funding cost.........
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Technical Consultant - ServiceNow Class of Legends 2025