Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Need JS to display notification based on condition

Posted on by

With zero JS skills ... seriously, no skills here ... I'm trying to write a function which will fire when value1 = value2.  I have specific fields I want to interrogate, but I'll address that once I know how to make the function work with a simple variable comparison.

This generates a "ReferenceError: 'changereport' is undefined.  What am I missing?

function changeReport ()

{

    value1 = 1

    value2 = 1

    msg = "123";

              if (value1 == value2)

              {             Xrm.Page.ui.setFormNotification("This is an INFORMATION notification.", "INFORMATION", msg)

                             var time = 5000;

                             //Wait the designated time and then remove

                             setTimeout(

                                           function () {

                                                          Xrm.Page.ui.clearFormNotification(msg);

                                                          },

                                           time

                                           );

},

}

*This post is locked for comments

  • Cyclefitness Profile Picture
    Cyclefitness on at
    RE: Need JS to display notification based on condition

    I figured it out.  I was missing the prefix on the attribute name.  I  am thrilled!!!  Thank you again.

  • Cyclefitness Profile Picture
    Cyclefitness on at
    RE: Need JS to display notification based on condition

    Now to replace the generic variable with a real one.  Something seems to be wrong with this attempt at getting the value and then evaluating it.  I must be missing something in the syntax?

    function changeReport()

    {

       var chgRptCount = Xrm.Page.getAttribute("countchangereports").getValue();

       msg = "123";

    if (chgRptCount > 0)

    { Xrm.Page.ui.setFormNotification("There are pending change reports not incorporated in the case.", "INFORMATION", msg)

    var time = 5000;

    //Wait the designated time and then remove

    setTimeout(

    function () {

    Xrm.Page.ui.clearFormNotification(msg);

    },

    time

    );

    }

    }

  • Cyclefitness Profile Picture
    Cyclefitness on at
    RE: Need JS to display notification based on condition

    After adding the missing ; after the var declarations and removing the stray , it WORKS!!!!   THANK YOU, everyone!

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Need JS to display notification based on condition

    Hi Debra,

    A couple of things. First I would get into the habit of adding the var keyword before declaring variables, but that is not the issue here. You had a lot of pointers above, but I saw one additional thing that might be causing the problem.

    //

    It looks like you have an unnecessary comma after the braces "}" (the one before the last one).

    Hope this is it.

  • Verified answer
    Luke Sartain Profile Picture
    Luke Sartain 1,266 on at
    RE: Need JS to display notification based on condition

    Also note the missing semi colons:

    value1 = 1

    value2 = 1

    Should be...

    value1 = 1;

    value2 = 1;

  • Cyclefitness Profile Picture
    Cyclefitness on at
    RE: Need JS to display notification based on condition

    EventHandler.png

    EventHandler.png

    Well ... not as close as I thought.  Still getting same error.  

  • RE: Need JS to display notification based on condition

    With JS you never know how close you are, very Schrödinger :D

  • Cyclefitness Profile Picture
    Cyclefitness on at
    RE: Need JS to display notification based on condition

    OMG, I'm that close??  LOL.  Let me see if that works now.

  • Cyclefitness Profile Picture
    Cyclefitness on at
    RE: Need JS to display notification based on condition

    Because I don't display the field on which the error is generated and because I don't like the error display on the field.  I want it to be on the notification bar at the top.

  • Verified answer
    RE: Need JS to display notification based on condition

    Hi,

    It looks like you're calling your method with changereport and it should be changeReport (capital R). Try to change that.

    Regards

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans