Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Clear Form level Notification using Javascript

Posted on by

Hi Guys,

I write Javascript for Form level notification, once the condition is match the error notification is come to form level.if the condition is doesn't match means i want to clear the form level notification. i write clear notification methods but it doesn't working.i don't know where i want to write the clear notification method.

this is my code. I need to know where i want to write clear notification line. I don't know where i made mistake

function cBlack() {
var vsEmail = Xrm.Page.getAttribute("new_email").getValue();
var vsMobilePhone = Xrm.Page.getAttribute("new_mobilephone").getValue();

if (vsEmail != null && vsMobilePhone != null) {
var rs_Email = vsEmail.toLowerCase().trim();
var rs_MobilePhone = vsMobilePhone.replace(/ +/g, "");

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/new_black?$select=emailaddress,new_mobilenumber", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
for (var i = 0; i < results.value.length; i++) {
var internalemailaddress = results.value[i]["emailaddress"];
var resultEmail = internalemailaddress.toLowerCase().trim();

var mobileNumber = results.value[i]["new_mobilenumber"];
var resultMobile = mobileNumber.replace(/ +/g, "");

if (rs_Email == resultEmail && rs_MobilePhone == resultMobile) {

Xrm.Page.ui.setFormNotification("This record is in blacklist ", "ERROR", "100");

//Xrm.Utility.alertDialog("This record is in blacklist")

}
else
{
rm.Page.ui.clearFormNotification("100");
}

}
}
else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();

}

else {
return true;
}
}

Please help me Guys..

Thank You

*This post is locked for comments

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Clear Form level Notification using Javascript

    Hi Dinesh,

    1. Please try to run "Xrm.Page.ui.clearFormNotification("100");" in watch window or console by pressing F12.

    2. One more thing, update your code as false at the end of line as shown below so that it will work synchronously.

    "req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/new_black?$select=emailaddress,new_mobilenumber", False);"

    Scenario:

    If you are able to clear notification from watch expression then there should be something missing in your logic which moves your debugger to "if condition" rather than else.

  • Suggested answer
    Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: Clear Form level Notification using Javascript

    Hi,

    As I said before you have right clear form notification code in onload and on change both

    Otherwise notification will not cleared when form open/loads
  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Clear Form level Notification using Javascript

    Hi,

    Try to do something like below -

    - define one Boolean variable at the beginning and set  value false.

    - inside for loop when matches found set Boolean value to true.

    - Outside for loop check the boolean value,  if it's true then set form notification else clear.

    - At the last where you are returning true  clear form notification.

    function cBlack() {

       var isExists= false;

       var vsEmail = Xrm.Page.getAttribute("new_email").getValue();

       var vsMobilePhone = Xrm.Page.getAttribute("new_mobilephone").getValue();

       if (vsEmail != null && vsMobilePhone != null) {

           var rs_Email = vsEmail.toLowerCase().trim();

           var rs_MobilePhone = vsMobilePhone.replace(/ +/g, "");

           var req = new XMLHttpRequest();

           req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/new_black?$select=emailaddress,new_mobilenumber", true);

           req.setRequestHeader("OData-MaxVersion", "4.0");

           req.setRequestHeader("OData-Version", "4.0");

           req.setRequestHeader("Accept", "application/json");

           req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

           req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

           req.onreadystatechange = function () {

               if (this.readyState === 4) {

                   req.onreadystatechange = null;

                   if (this.status === 200) {

                       var results = JSON.parse(this.response);

                       for (var i = 0; i < results.value.length; i++) {

                           var internalemailaddress = results.value[i]["emailaddress"];

                           var resultEmail = internalemailaddress.toLowerCase().trim();

                           var mobileNumber = results.value[i]["new_mobilenumber"];

                           var resultMobile = mobileNumber.replace(/ +/g, "");

                           if (rs_Email == resultEmail && rs_MobilePhone == resultMobile && ) {

                                    isExists= true;

                            }

                       }

    if(isExists == true)

                       {

    Xrm.Page.ui.setFormNotification("This record is in blacklist ", "ERROR", "100");

                       }

                       else

                        {

              Xrm.Page.ui.clearFormNotification("100");

                          }

                   }

                   else {

                       Xrm.Utility.alertDialog(this.statusText);

                   }

               }

           };

           req.send();

       }

    else {

           Xrm.Page.ui.clearFormNotification("100");

           return true;

       }

    }

  • Verified answer
    Mahadeo Matre Profile Picture
    Mahadeo Matre 17,021 on at
    RE: Clear Form level Notification using Javascript

    I think someone already mentioned in above.. you need to clear notification first 

    try changing your code 

    function cBlack() {
     Xrm.Page.ui.clearFormNotification("100"); 
     
        var vsEmail = Xrm.Page.getAttribute("new_email").getValue();
        var vsMobilePhone = Xrm.Page.getAttribute("new_mobilephone").getValue();
    
        if (vsEmail != null && vsMobilePhone != null) {
            var rs_Email = vsEmail.toLowerCase().trim();
            var rs_MobilePhone = vsMobilePhone.replace(/ +/g, "");
    
            var req = new XMLHttpRequest();
            req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/new_black?$select=emailaddress,new_mobilenumber", true);
            req.setRequestHeader("OData-MaxVersion", "4.0");
            req.setRequestHeader("OData-Version", "4.0");
            req.setRequestHeader("Accept", "application/json");
            req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
            req.onreadystatechange = function () {
                if (this.readyState === 4) {
                    req.onreadystatechange = null;
                    if (this.status === 200) {
                        var results = JSON.parse(this.response);
                        for (var i = 0; i < results.value.length; i++) {
                            var internalemailaddress = results.value[i]["emailaddress"];
                            var resultEmail = internalemailaddress.toLowerCase().trim();
    
                            var mobileNumber = results.value[i]["new_mobilenumber"];
                            var resultMobile = mobileNumber.replace(/ +/g, "");
    
                            if (rs_Email == resultEmail && rs_MobilePhone == resultMobile) {
    
                                Xrm.Page.ui.setFormNotification("This record is in blacklist ", "ERROR", "100");
    
                                //Xrm.Utility.alertDialog("This record is in blacklist")
    
                            }
                           /* else {
                                Xrm.Page.ui.clearFormNotification("100"); 
                            }*/
    
                        }
                    }
                    else {
                        Xrm.Utility.alertDialog(this.statusText);
                    }
                }
            };
            req.send();
    
        }
    
        else {
            return true;
        }
    }



  • Suggested answer
    Priyesh Profile Picture
    Priyesh 7,392 User Group Leader on at
    RE: Clear Form level Notification using Javascript

    Hi,

    Yo can refer my blog on an application of setFormNotification and clearFormNotification in v9 -d365demystified.com/.../use-setformnotification-client-side-js-in-d365-v9-while-real-time-workflow-is-executing

  • DineshRaja Profile Picture
    DineshRaja on at
    RE: Clear Form level Notification using Javascript

    I call the function while am change the filed value in email field and mobile number field also..

  • Suggested answer
    Mahadeo Matre Profile Picture
    Mahadeo Matre 17,021 on at
    RE: Clear Form level Notification using Javascript

    Just wondering.. when your function called?

    Is it called when you are trying to clear notification?

    if it is called, then first clear notification and only set notification when condition matches.

  • DineshRaja Profile Picture
    DineshRaja on at
    RE: Clear Form level Notification using Javascript

    Sorry Guys i write the code with Xrm.page but still i can't able to clear the form notification

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Clear Form level Notification using Javascript

    Hi Dinesh,

    As suggested above you wrote "rm" instead of "Xrm"

    function cBlack() {
        var vsEmail = Xrm.Page.getAttribute("new_email").getValue();
        var vsMobilePhone = Xrm.Page.getAttribute("new_mobilephone").getValue();
    
        if (vsEmail != null && vsMobilePhone != null) {
            var rs_Email = vsEmail.toLowerCase().trim();
            var rs_MobilePhone = vsMobilePhone.replace(/ +/g, "");
    
            var req = new XMLHttpRequest();
            req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/new_black?$select=emailaddress,new_mobilenumber", true);
            req.setRequestHeader("OData-MaxVersion", "4.0");
            req.setRequestHeader("OData-Version", "4.0");
            req.setRequestHeader("Accept", "application/json");
            req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
            req.onreadystatechange = function () {
                if (this.readyState === 4) {
                    req.onreadystatechange = null;
                    if (this.status === 200) {
                        var results = JSON.parse(this.response);
                        for (var i = 0; i < results.value.length; i++) {
                            var internalemailaddress = results.value[i]["emailaddress"];
                            var resultEmail = internalemailaddress.toLowerCase().trim();
    
                            var mobileNumber = results.value[i]["new_mobilenumber"];
                            var resultMobile = mobileNumber.replace(/ +/g, "");
    
                            if (rs_Email == resultEmail && rs_MobilePhone == resultMobile) {
    
                                Xrm.Page.ui.setFormNotification("This record is in blacklist ", "ERROR", "100");
    
                                //Xrm.Utility.alertDialog("This record is in blacklist")
    
                            }
                            else {
                                Xrm.Page.ui.clearFormNotification("100"); 
                            }
    
                        }
                    }
                    else {
                        Xrm.Utility.alertDialog(this.statusText);
                    }
                }
            };
            req.send();
    
        }
    
        else {
            return true;
        }
    }


  • Verified answer
    Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: Clear Form level Notification using Javascript

    Hi,

    Add Xrm.Page.ui.clearFormNotification("100"); in your first line of function. if your code doest call every time when form loads then add it on form onload aswell. as per logic it will show/hide only when it pass through if(vsEmail != null && vsMobilePhone != null) statement.

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans