- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2020 04:53 AM
Hi,
Through Business rule i am getting right Percentage , but client wants onChange
Total Revenue of Project ( $ ) - field Integer type
Project Profitability ( $ ) - field Integer type
Formula : (U-R)/U
var projectrevenue = g_form.getValue('u_total_revenue_per_milestone'); //U//
var projectcost = g_form.getValue('u_project_profitability'); //R//
var percentage=(projectrevenue -projectcost )/projectrevenue
var percentagevalue = percentage * 100;
alert('percentage :'+percentagevalue);
g_form.setValue('u_gpm', percentagevalue.toFixed(2));
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2020 05:52 AM
Try below.
var projectrevenue = g_form.getValue('u_total_revenue_per_milestone').replace(/,/g,'')); //U//
var projectcost = g_form.getValue('u_project_profitability').replace(/,/g,'')); //R//
var pr = parseFloat(projectrevenue);
var pc =parseFloat(projectcost);
alert(pr + "---" + pc);
var percentage = pr - pc;
alert(percentage);
var uu = percentage / pr;
alert(uu);
var percentagevalue = parseFloat(percentage * 100);
alert('percentage :' + percentagevalue);
g_form.setValue('u_gpm', percentagevalue.toFixed(2));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2020 07:02 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2020 07:16 AM
Oh yes, Totally forgot that it can be only used in server side script.
so try
var projectrevenue = g_form.getValue('u_total_revenue_per_milestone'); //U//
var projectcost = g_form.getValue('u_project_profitability'); //R//
var pr = parseInt(projectrevenue);
var pc =parseInt(projectcost);
alert(pr + "---" + pc);
var percentage = pr - pc;
alert(percentage);
var uu = percentage / pr;
alert(uu);
var percentagevalue = parseFloat(percentage * 100);
alert('percentage :' + percentagevalue);
g_form.setValue('u_gpm', percentagevalue.toFixed(2));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2020 10:46 PM
Hello,
A solution for this, when we want to use an integer field for a calculation we don't need the comma's.
So add the attribute "format=none" to the dictionary entry of the respective integer fields. This will drop the comma allowing the calculation to work.
Let me know if it worked.
Regards,
Mihir Rathod.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2020 02:35 AM