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 :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Hide/Show Activity Home (View) Cancel button based on activity type and its owner

(1) ShareShare
ReportReport
Posted on by
Hi Expert,
 
Have a current requirement, to say, if the activity type is Appointment and Appointment Activity owner is /Portal User/, show the Activity home page ribbon button /Cancel/, otherwise hide it. I try to user Ribbon Workbench Enable Rule to get it work. My code as below,
 
async function hideHomePageCancelBtn(firstSelectedItemId) {    debugger;    const activity = await Xrm.WebApi.retrieveRecord(        'activitypointer',        firstSelectedItemId,        '?$select=activitytypecode',        /?$expand=appointment($select=ownerid)/    );    const isAptType = activity['activitytypecode'];    const owner = appointment['ownerid']    if (isAptType === appointment) {        if (owner === 'Portal User')            return true;    } else {        return false;    }}
After created Enable Rule and attached to the Command, tested it, not work.
 
The rule set up as below
 
//
 
Any suggestions/solutions are welcome and  appreciated!
 
  • Suggested answer
    SidKicksin Profile Picture
    10 User Group Leader on at
    Hey 

    Did you checked the response of your enable rule on the UI? 
    If not, please check it through - Debug Ribbon button customization using Command Checker in Dynamics 365 CE Unified Interface | D365 Demystified.

    Let me know if this works.
    Thanks!
  • Verified answer
    Dengliang Li Profile Picture
    Microsoft Employee on at
    Hi,
     
    You can hide the button by getting the HTML element for the cancel button and setting its style to display=none.
     
    The code is shown below.
     
    async function hideHomePageCancelBtn(firstSelectedItemId) {  
           
        const activity = await Xrm.WebApi.retrieveRecord( 'activitypointer',firstSelectedItemId,'?$select=activitytypecode&$expand=owninguser($select=fullname)');    
        const isAptType = activity.activitytypecode;    
        const owner = activity.owninguser.fullname;
        //get the cancle button html element
        var cancleButton = parent.parent.window.document.querySelector("button[aria-label='Cancel']");  
        if(cancleButton !=null){
            if (isAptType === "appointment") {
                if (owner !== 'System Administrator'){
                    // hide the cancle button
                    cancleButton.style.display ="none";
                }
             
            }
        }else{
            // Wait for some time to check again if the page elements are loaded.
            setTimeout(hideHomePageCancelBtn, 10, firstSelectedItemId);
        }
       
    }
     
    The final result is shown below, hiding the /Cancel/ button when the owner is not the System Administrator.
     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more.
    If you have further questions, please feel free to contact me .
     
    Best Regards,
    Dengliang Li
     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 46 Super User 2026 Season 2

#2
Travis South Profile Picture

Travis South 35

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 33 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans