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

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 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans