web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Clear Form level Notification using Javascript

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at

    Hi..

    there is syntax error in your code

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

    it should be

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

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    try to include it where you are returning true, you can remove above else part

    else

    {

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

    return true;

    }

  • Verified answer
    Sreevalli Profile Picture
    3,264 on at

    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.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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;
        }
    }


  • DineshRaja Profile Picture
    on at

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

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at

    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
    on at

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

  • Suggested answer
    Priyesh Profile Picture
    7,396 User Group Leader on at

    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

  • Verified answer
    Mahadeo Matre Profile Picture
    17,021 on at

    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
    gdas Profile Picture
    50,091 Moderator on at

    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;

       }

    }

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans