Division Calculation within CRM 2011 RRS feed

  • Question

  • Hey guys,

    I need some help on this. Its fairly basic but I have very little knowledge of JScript and have trouble pulling off tasks that use it. Basically, I have a custom field and I want it to be the division of two other fields. I have a "Opportunities Won" field and I have a "Total Opportunities" field. I need to create a third custom field that does a division to get the average won (new_opportunities / new_totalopportunities ) It would be nice if this could be done using a workflow, because then I wouldnt have to open the form to update the number, but JScript is fine if thats the only way. If you do tell me Jscript, can you please also tell me if I should put it into the OnLoad, or OnSave and also what function I should call? Again, Im bad with Jscript. Thanks.

    Oh yeah, and these are all using floating point numbers.
    Wednesday, September 19, 2012 4:24 PM


  • You could use JavaScript like this - function would be bound to the OnChange event of the 2 fields making up the calculation

    function Calculate() {
        if (Xrm.Page.getAttribute("new_test1").getValue() != null && Xrm.Page.getAttribute("new_test2").getValue() != null) {
            if (Xrm.Page.getAttribute("new_test1").getValue() != 0 && Xrm.Page.getAttribute("new_test2").getValue() != 0) {
                Xrm.Page.getAttribute("new_test1").getValue() / Xrm.Page.getAttribute("new_test2").getValue());

    Creating A JavaScript Web Resource

    Use A JavaScript Web Resource In Your Form

    Or you could look into this solution - it allows performing calculations like division using a workflow

    CRM Manipulation Library

    Jason Lattimer

    Wednesday, September 19, 2012 5:01 PM