Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Custom Java - Not working

Posted on by

I am trying to get the value of a field to display if its below 7.00


Although I keep getting an error every time I try to run it, but can't see where I'm going wrong?

Here's the code:

Function checkmargin()
{
    var margin = Xrm.Page.getAttribute("ro_margin").getValue()
    if (margin < 7.0)
    {
        //display the value within a warning box
        alert("Margin lower than Target", null, null, "WARNING", 500, 200);
    }
}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Custom Java - Not working

    feel free to mark posts as answers if they helped you!

  • Blair24 Profile Picture
    Blair24 on at
    RE: Custom Java - Not working

    Thanks for the help! Really appreciated!

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Custom Java - Not working

    Some things I would try:

    Write Function as function, with a lowercase f.

    Missing semicolon at .getValue();

    Unless ro_margin is a required field, you should check for null value as per semosby's instruction

    Try a simplified alert instead, like this: alert("Margin lower than target");

    Make sure margin is a decimal value, else check it for < 7 rather than < 7.0.

  • Verified answer
    semosby Profile Picture
    semosby 230 on at
    RE: Custom Java - Not working

    HI Blair.  

    2 things.  If the attached is your actual code, then you're going to receive syntax errors. If is a facsimile of your code, paste your code.  

    Also, it is a good idea to check the field to make certain it is on the form.  For example:

       var margin = Xrm.Page.getAttribute("ro_margin");  

       if (margin == null || margin == 'undefined' ) return;

    And... You can use "Xrm.Page.ui.setFormNotification(message, level, uniqueId)" to set the crm form notification instead of popping an alert box which might get blocked by users' browser settings.

    And finally, if you don't mind sharing your error message, I'm certain you'll get a ton of other suggestions.  

  • Verified answer
    cosmic-ian Profile Picture
    cosmic-ian 40 on at
    RE: Custom Java - Not working

    I'm totally not an expert but it looks like there is a missing semicolon :

    var margin = Xrm.Page.getAttribute("ro_margin").getValue() ;

  • Vighnesh Profile Picture
    Vighnesh 1,942 on at
    RE: Custom Java - Not working

    Hi Blair,

    Firstly your code has syntax errors. You should provide more info on the field & its datatype you are trying to control.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans