Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Notification with JS

Posted on by 60

Hi everyone,
Here is my JS code

function Check () {
var i = Xrm.Page.getAttribute("new_individual").getSeletedOption();
if( i == Yes){
var message = Xrm.Page.getAttribute("parenaccountid").getValue();
var type = “please make change in”;


Xrm.Page.ui.setFormNotification(message, type);
}
}

2311.Capture1.PNG   1307.Capture2.PNG

In my form I have Individual field which one have two option "Yes" or "No"
If user choose "Yes" it should appear notification with parent account message.

But it's no matter what user choose, it's always push error with

58332.Capture.PNG

ReferenceError: Check is not defined
at eval (eval at RunHandlerInternal (salescrmdev.carsondellosa.com/.../ClientApiWrapper.aspx, <anonymous>:1:1)
at RunHandlerInternal (salescrmdev.carsondellosa.com/.../ClientApiWrapper.aspx
at RunHandlers (salescrmdev.carsondellosa.com/.../ClientApiWrapper.aspx
at ExecuteHandler (salescrmdev.carsondellosa.com/.../ClientApiWrapper.aspx
at Mscrm.TurboForm.Control.CustomScriptsManager.$Cb_1 (salescrmdev.carsondellosa.com/.../formcontrols.js
at Mscrm.TurboForm.Control.CustomScriptsManager.executeHandler (salescrmdev.carsondellosa.com/.../formcontrols.js
at Mscrm.TurboForm.Control.CustomScriptsManager.executeHandlerByDescriptor (salescrmdev.carsondellosa.com/.../formcontrols.js
at salescrmdev.carsondellosa.com/.../formcontrols.js
at salescrmdev.carsondellosa.com/.../global.ashx
at Mscrm.TurboForm.Control.Data.BooleanDataAttribute.fireOnChange (salescrmdev.carsondellosa.com/.../formcontrols.js

Please help me to resolve it, Thanks.

*This post is locked for comments

  • Suggested answer
    Kalpavruksh D365 CoE Profile Picture
    Kalpavruksh D365 CoE 2,545 on at
    RE: Notification with JS

    Hi,

    1. Can you try to remove the space between check and bracket()?

    2. After that can you check function name you specified onChange of Individual field doesnt contain any space in the name before or after Check.

    Please refer below link:

    www.linkedin.com/.../

    3. Can you comment your JS code inside for a while and add a simple alert to make sure your function is fired.

    4. Once the function is fired, uncomment the code and correct the code as follows:

    function Check(){

       var individual = Xrm.Page.getAttribute("new_individual").getValue();

       if(individual==false){

           var type = "please make change in";

           Xrm.Page.ui.setFormNotification(type,"INFORMATION","IndiviualMessage" );

       }

       else {

           Xrm.Page.ui.clearFormNotification('IndiviualMessage');

       }

    }

  • ajyendra Profile Picture
    ajyendra 1,730 on at
    RE: Notification with JS

    Hi,

    setFormNotification()  has wrong parameter

    docs.microsoft.com/.../setformnotification

    try this

    formContext.ui.setFormNotification(type , "INFORMATION", '1');

       // Wait for 5 seconds before clearing the notification

    window.setTimeout(function () { formContext.ui.clearFormNotification('1'); }, 5000);

  • Suggested answer
    NODAL Profile Picture
    NODAL 860 on at
    RE: Notification with JS

    Hi Vardan,

    I would recommend if you can use a simple "Business Rule" as follows.

    pastedimage1568122244671v1.png

    In Condition you can put "If Individual is Yes"

    Then show recommendation against "Parent Account".

    Regards,

    Ketan

  • Vardan  Profile Picture
    Vardan 60 on at
    RE: Notification with JS

    I do something like this

    function Check() {

    var i = Xrm.Page.getAttribute("new_individual").getSeletedOption().text;

    if( i ==="Yes"){

    var name = Xrm.Page.getAttribute('parentaccountid").getValue()[0].name;

    var type = “please make change in”;

    Xrm.Page.ui.setFormNotification(type,name,"INFORMATION" );

    }

    }

    Yes I know there is something wrong, can you help to correct?

    thanks.

  • Verified answer
    ajyendra Profile Picture
    ajyendra 1,730 on at
    RE: Notification with JS

    Hi,

    You can try

    var name = Xrm.Page.getAttribute('<FIELD_NAME>').getValue()[0].name;

    (you can also use "id":  Xrm.Page.getAttribute('<FIELD_NAME>').getValue()[0].id;)

  • Vardan  Profile Picture
    Vardan 60 on at
    RE: Notification with JS

    Hi Ketan Rajpurohit,

    Just alert for user to remember do something with parent account.

    I want to put it notification alert parent account link.

  • Suggested answer
    NODAL Profile Picture
    NODAL 860 on at
    RE: Notification with JS

    Hi Vardan,

    Seems to be some syntax issue.

    Try below script.

    function Check() {

    var i = Xrm.Page.getAttribute("new_individual").getSeletedOption().text;

    if( i ==="Yes"){

    //var message = Xrm.Page.getAttribute("parenaccountid").getValue();

    var type = “please make change in”;

    Xrm.Page.ui.setFormNotification(type,"INFORMATION" );

    }

    }

    Message cannot be a lookup object.

    What message you want to display?

    Is it information or error or warning

    Regards,

    Ketan

  • ajyendra Profile Picture
    ajyendra 1,730 on at
    RE: Notification with JS

    Hi,

    Still get same error or something else?

    thanks

    Ajyendra Singh

  • Vardan  Profile Picture
    Vardan 60 on at
    RE: Notification with JS

    I removed space but still don't work

  • Suggested answer
    ajyendra Profile Picture
    ajyendra 1,730 on at
    RE: Notification with JS

    Hi ,

    I think it a Syntax Issue

    There is a space between Check and () remove it function Check() instead of function Check ()

    Thanks

    Ajyendra

    Please mark verified if answer is helpful for you.

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