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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Form Notification - Show and Clear

(0) ShareShare
ReportReport
Posted on by 123
Hi,
 
I am trying to add a form level notification to show a message, and when a field is marked to Yes (two option), the notification clears.
 
This piece of script work to show the notification.
 
function FormNotificationInfo(executionContext) {
        var formContext = executionContext.getFormContext();
        var infoMessage = /This is Warning Notification./
        var infoId = Math.random().toString();
        //information notification
        formContext.ui.setFormNotification(infoMessage, /WARNING/, infoId);
        }
 
So I wrote something like this but it doesn't seem to work.
 
function FormNotificationInfo() {
    
        var value = Xrm.Page.getAttribute(/sandm_shownotification/).getValue();
        var infoMessage = /This is Warning Notification./
        
        if(value == 1){
       //clear error notification
       formContext.ui.clearFormNotification(888);
        }
        if(value == 0){
        //information notification
        formContext.ui.setFormNotification(infoMessage, /WARNING/, 888);
        }
        
}
 
Can someone help please. I not the best at writing scripts.
 
Thanks
Damesh
I have the same question (0)
  • Suggested answer
    Leah Ju Profile Picture
    Microsoft Employee on at
    Hi Damesh,
    1.In your second code, you are missing the execution context and getFormContext that you used in the first code.
    2.Uisng this syntax to get value from the notification field.
    formContext.getAttribute(arg).getValue()
     
    Please refer to the following code:
    function FormNotificationInfo(executionContext) {
        var formContext = executionContext.getFormContext();
        var value = formContext.getAttribute("cre80_shownotification").getValue();
        var infoMessage = "This is Warning Notification.";
    
        if (value == 1)// field label is No
        {
            //clear error notification
            formContext.ui.clearFormNotification(888);
        }
        if (value == 0)// field label is Yes
        {
            //information notification
            formContext.ui.setFormNotification(infoMessage, "WARNING", 888);
        }
    }
     
    My notification field:

    I hope you can mark my answer verified if it answer your question! If you have any questions, please feel free to contact me.
    Regards,
    Leah
     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 171 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 83

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans