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)

Simple Jscript not working

(0) ShareShare
ReportReport
Posted on by 1,195

I am having trouble getting a calculation function to work. I have 3 fields all of which are floating point numbers with a precision of '2'. Two fields have a range of 0.00 to 1,000,000.00 and another has 0.00 to 1.00 (percentage). The goal is to take 'newprojectcomplete' multply it by 'newcontracthours' and populate the result value to 'targethours'. Keep getting the same error no matter how I write the code. "Error: The value of the property 'Calc_target' is null or undefined, not a function object"

 

Any help?

 

Here is the function I wrote:

function Calc_target() {

Xrm.Page.data.entity.attributes.get("test_targethours).setValue() = Xrm.Page.data.entity.attributes.get("test_newprojectcomplete").getValue() * Xrm.Page.data.entity.attributes.get("test_newcontracthours").getValue();

}

Thanks

*This post is locked for comments

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

    A couple of things:

    There was a typo - missing a " after test_targethours.

    Then, when setting a field value, the value goes inside the () of setValue.

    So it should look something like this:

    function Calc_target() {
        var val = Xrm.Page.data.entity.attributes.get("test_newprojectcomplete").getValue() * Xrm.Page.data.entity.attributes.get("test_newcontracthours").getValue();
        Xrm.Page.data.entity.attributes.get("test_targethours").setValue(val);
    }
    
  • Michael Mertz Profile Picture
    1,195 on at

    Thanks Jason,

    Still getting the same error. This is based on an OnChange event for the 'projectcomplete' would that make a difference?

    function Calc_target1() {

       var val = Xrm.Page.data.entity.attributes.get("test_newprojectcomplete").getValue() * Xrm.Page.data.entity.attributes.get("test_newcontracthours").getValue();

       Xrm.Page.data.entity.attributes.get("test_targethours").setValue(val);

    }

  • jlattimer Profile Picture
    24,564 on at

    Did you publish the web resource after updating ? I also noticed you added a 1 to the method name, did you update in the form event and publish?

  • Michael Mertz Profile Picture
    1,195 on at

    Yea, I did it a few times to make sure. The '1' was just added for versioning. I'm not sure what is going on. I checked all my field names to verify, published changes, added both the form library and the event handler.

  • Michael Mertz Profile Picture
    1,195 on at

    I got it to work. I deleted out some of the other functions I had in there and it worked. I guess it didn't like having multiple functions in the file..weird.

  • Verified answer
    jlattimer Profile Picture
    24,564 on at

    2 sharing the same name would be cause for an issue if that was the case.

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