web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error in field calculation

(0) ShareShare
ReportReport
Posted on by 590

I am trying to get a field to do a simple calculation and put the result in another field.  Here is what I have

Field 1 = Estimated Project Amount (estimated amount of a project)

Field 2= Fee % (Fee percentage we'll apply to that)

Field 3 = Construction Fee (the result - for instance 15% on a $1,000,000 project would result in 150,000)

In the Fee% field i have the following event in the Fee% field - On Change

function calculate()

{

 var val1 = Xrm.Page.entity.attributes.get('new_estimatedprojectamt").getValue();

 var val2 = Xrm.Page.entity.attributes.get("new_fee").getValue();

 if (val1 == null) return;

 if (val2 == null) return;

 var result = val1 * val2;

 Xrm.Page.entity.attributes.get("new_constructionfees").setValue(result);

 }

When i try to enter a number into the field i get the following error

There was a error with thie field's customized event

Field: new_fee

Event:onchange

Error:'calculate' is undefined

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    jlattimer Profile Picture
    24,564 on at

    You have mis-matched quotation marks in the line setting val1

     

    function calculate()
    {
        var val1 = Xrm.Page.entity.attributes.get("new_estimatedprojectamt").getValue();
        var val2 = Xrm.Page.entity.attributes.get("new_fee").getValue();
        if (val1 == null) return;
        if (val2 == null) return;
        var result = val1 * val2;
        Xrm.Page.entity.attributes.get("new_constructionfees").setValue(result);
    }
    
  • Brad Baumert Profile Picture
    590 on at

    Thanks for the quick response.

    I now get the following error:

    There was an error with this fields customized event.

    Field: new_fee

    Event: onchange

    Error: Unable to get value of the property 'attributes': object is null or undefined.

  • Suggested answer
    jlattimer Profile Picture
    24,564 on at

    Use use Xrm.Page.data.entity...

     

    function calculate() {
        var val1 = Xrm.Page.data.entity.attributes.get("new_estimatedprojectamt").getValue();
        var val2 = Xrm.Page.data.entity.attributes.get("new_fee").getValue();
        if (val1 == null) return;
        if (val2 == null) return;
        var result = val1 * val2;
        Xrm.Page.data.entity.attributes.get("new_constructionfees").setValue(result);
    }
    
  • Brad Baumert Profile Picture
    590 on at

    Jason, again thanks for your response.  I made the change but still get the exact same error.

    I apologize for my ingnorance on this issue but this is my first attempt and adding this type of functionality to CRM.

  • jlattimer Profile Picture
    24,564 on at

    After updating the web resource - did you publish it?

  • Brad Baumert Profile Picture
    590 on at

    I did publish it - twice for good measure.  Do I need any type of code\formula in the "Construction Fee" field which will simply show the result?

  • jlattimer Profile Picture
    24,564 on at

    Nothing special besides the field actually being present on the form. Just to verify - is the schema name of the field "new_constructionfees" or "new_constructionfee" (not plural)? The code implies it is plural but you just referred to it as singular.

    I tested the code with matching fields - maybe just double check the field names.

  • Brad Baumert Profile Picture
    590 on at

    "new_constructionfees" is correct.  I double checked the actual schema name on all fields to ensure they match the code.

  • Brad Baumert Profile Picture
    590 on at

    Does it matter they the "type" is on the custom field that has been created?  The new_fee for example is a Decimal Number.  The Construction Fees is a whole number.

    Also, i did have a typo in the code on construction_fees

  • Brad Baumert Profile Picture
    590 on at

    Ok.  The new_fee field now accepts the entry but there is nothing returning in the the new_constructionfees field.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans