web
You’re offline. This is a read only version of the page.
close
Skip to main content
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,562 on at
    RE: Error in field calculation

    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
    RE: Error in field calculation

    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,562 on at
    RE: Error in field calculation

    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
    RE: Error in field calculation

    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,562 on at
    RE: Error in field calculation

    After updating the web resource - did you publish it?

  • Brad Baumert Profile Picture
    590 on at
    RE: Error in field calculation

    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,562 on at
    RE: Error in field calculation

    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
    RE: Error in field calculation

    "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
    RE: Error in field calculation

    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
    RE: Error in field calculation

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans