Reputation: 11
I've created two workflows that count the number of leads and the number of a custom entity called Legal cases. I would like to come up with a ratio for reporting purposes that calculates legal cases/leads. The workflow updates two fields on the forms (leads and cases) every time one of the entity is created. I tried to use the following code:
function calculate()
{
var val1 = Xrm.Page.entity.attributes.get['getlead_casecounters'].getValue();
var val2 = Xrm.Page.entity.attributes.get['getlead_leadcounter'].getValue();
if(val1==null)return;
if(val2==null)return;
var result = val1 / val2;
Xrm.Page.entity.attributes.get['getlead_casetoleadratio'].setValue(result);
}
The problem is that the casetoleadratio field doesn't appear to update. Any thoughts or recommendations?
Upvotes: 0
Views: 336
Reputation: 548
The best way to show arithmetic calculations is by coding them directly inside your reports. There’s no good place to store these calculations in CRM anyway since CRM only knows how to store data per a single record.
Eventually, any elegant solution that needs calculation beyond the basics (max, average, min, sum, count, percentage) will require some kind of coding, which it seems you’re trying to avoid.
For the record, client side (javaScript) functions that you include in your forms only run inside the your browser in the context of a single record that you create or update. WF will not / cannot run these functions. To run functionally in WF you need to write custom workflow activities or plug-ins using c# for example.
Upvotes: 0
Reputation:
Take a look at https://stackoverflow.com/a/11923059/2295317 I think it's exactly what you are trying to do. Basically that last line should be:
Xrm.Page.getAttribute("getlead_casetoleadratio").setValue(result);
If that doesn't do it then maybe try to force a save using:
Xrm.Page.Data.Entity.Save();
as seen here: https://stackoverflow.com/a/18635688/2295317
Upvotes: 0