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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Setting Notification

(0) ShareShare
ReportReport
Posted on by 123

Hi 

Hope someone can help. I seem to be going round in circles

I have created a web resource file with the following JavaScript.


function setConsentPreferenceNotification() {

var consentpreferencegiven = Xrm.Page.getAttribute("acg_consentpreferencegiven").getValue();

if (consentpreferencegiven == "805270001") {

Xrm.Page.ui.setFormNotification("YOu must get Consent", "INFO", "805270001");

}

else {

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

}

}

 


Ive created a field Yes/No options set and named it ConsentPreferenceGiven. Set default value to NO.

Then went to form properties and added this form to Form Libraries and Event Handler (named function to ConsentPreferenceNotification)

But i keep getting an error. 

Have i missed out a step or written the code wrong?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Damesh ,

    You are saying that you created Yes/No options , is this two options field or optionset?

    Seems your code is fine you can debug and check whether your code else part executing. 

    Also try with this - 

    function setConsentPreferenceNotification() {
        var consentpreferencegiven = Xrm.Page.getAttribute("acg_consentpreferencegiven").getValue();
        if (consentpreferencegiven == "805270001") {
            Xrm.Page.ui.setFormNotification("YOu must get Consent", "INFO", 123);
        }
        else {
            Xrm.Page.ui.clearFormNotification(123);
        }
    }


    You can also try with field notification-

    function setConsentPreferenceNotification() {
        var consentpreferencegiven = Xrm.Page.getAttribute("acg_consentpreferencegiven").getValue();
        if (consentpreferencegiven == "805270001") {
            Xrm.Page.getControl("acg_consentpreferencegiven").setNotification("YOu must get Consent", "INFO");  
        }
        else {
            Xrm.Page.getControl("acg_consentpreferencegiven").clearNotification();
        }
    }


    Hope this helps .

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

    Hello,

    Your code seems fine just your using wrong value while clearning, you can try to debug and see where it's failing

    function setConsentPreferenceNotification() {

    var consentpreferencegiven = Xrm.Page.getAttribute("acg_consentpreferencegiven").getValue();

    if (consentpreferencegiven == "805270001") {

    Xrm.Page.ui.setFormNotification("YOu must get Consent", "INFO", "805270001");

    }

    else {

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

    }

    }

  • Damesh Peri Profile Picture
    123 on at

    Thanks Guys. My silly mistake.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April 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