Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How to hide button in ribbon workbench if form is dirty

(0) ShareShare
ReportReport
Posted on by 32

I have a requirement to hide a button in the ribbon if the form is dirty (i.e. in a state of unsaved). 

I know I can use a function calling the getIsDIrty() method, but I am unable to get this working. 

I have created a custom enable rule as below with the function below. 

I understand I may have the Invert Result wrong, but whichever way I try I do not see the button. (Note I also have a rule that on create this button is hidden).

Do I need to make use of RefreshRibbon somewhere to pick up the new rules?. If so where can I use this so it gets fired? 

pastedimage1663851745676v1.png


function checkUnsavedChanges(primaryControl)

{

return Xrm.Page.data.entity.getIsDirty();

}

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How to hide button in ribbon workbench if form is dirty

    Hello,

    Add the following code to the onload event handler of the form:

    function onLoad(executionContext) {
    	var formContext = executionContext.getFormContext();
    
    	formContext.data.entity.attributes.forEach(function(a){
    		a.addOnChange(function(){
    			formContext.ui.refreshRibbon();
    		});
    	});
    }

  • Suggested answer
    Abdul Wahab Profile Picture
    12,085 Moderator on at
    RE: How to hide button in ribbon workbench if form is dirty

    Hi

    Please add formContext.ui.refreshRibbon(refreshAll) on onchange of the column.

    If I answer your question then please mark it as verified.

    Let me know if I can provide you with more details.

    Thanks

    Regards,

    Abdul Wahab

    Power Platform & Customer Engagement Developer/Lead/Solution Architecture/Project Manager

    Direct/WhatsApp:+923323281237

    E-mail: abdulwahabubit@outlook.com

    Skype: abdul.wahabubit

    Linkedin: www.linkedin.com/.../

  • HK Profile Picture
    32 on at
    RE: How to hide button in ribbon workbench if form is dirty

    Hey, thanks for getting back.

    I applied the changes as above and unfortunately when I change a field, I still see the button.

    Note I am not saving the data, the goal is to get the button to hide before saving, does that matter?

  • Verified answer
    Abdul Wahab Profile Picture
    12,085 Moderator on at
    RE: How to hide button in ribbon workbench if form is dirty

    Hi Alex Br,

    Make Default = False

    The below code will resolve your problem.

    function checkUnsavedChanges(_primaryControl) {
        var isNotFormDirty = true;
        var formContext = _primaryControl;
        attributes = formContext.data.entity.attributes.get();
        if (attributes != null) {
            for (var i in attributes) {
                if (attributes[i].getIsDirty()) {
                    // Display the name and value of the attribute that has changed
                    isNotFormDirty = false;
                    break;
                }
            }
        }
        return isNotFormDirty;
    }

    If I answer your question then please mark it as verified.

    Let me know if I can provide you with more details.

    Thanks
    Regards,

    Abdul Wahab
    Power Platform & Customer Engagement Developer/Lead/Solution Architecture/Project Manager
    Direct/WhatsApp: 923323281237
    E-mail: abdulwahabubit@outlook.com
    Skype: abdul.wahabubit
    Linkedin: www.linkedin.com/.../

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 82 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans