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 :
Customer experience | Sales, Customer Insights,...
Answered

How to hide button in ribbon workbench if form is dirty

(0) ShareShare
ReportReport
Posted on by 36

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

}

I have the same question (0)
  • Verified answer
    Abdul Wahab Profile Picture
    12,119 Moderator on at

    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/.../

  • HK Profile Picture
    36 on at

    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?

  • Suggested answer
    Abdul Wahab Profile Picture
    12,119 Moderator on at

    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/.../

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

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

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 > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 128 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 95

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans