Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

How to hide button in ribbon workbench if form is dirty

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
    a33ik 84,323 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
    Abdul Wahab 12,070 Super User 2024 Season 1 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
    HK 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
    Abdul Wahab 12,070 Super User 2024 Season 1 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans