Skip to main content

Notifications

Announcements

No record found.

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

  • Damesh Peri Profile Picture
    Damesh Peri 123 on at
    RE: Setting Notification

    Thanks Guys. My silly mistake.

  • Verified answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Setting Notification

    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");

    }

    }

  • Verified answer
    gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: Setting Notification

    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 .

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans