web
You’re offline. This is a read only version of the page.
close
Skip to main content
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!
 
I have the same question (0)
  • Suggested answer
    SidKicksin Profile Picture
    10 User Group Leader on at
    Hide/Show Activity Home (View) Cancel button based on activity type and its owner
    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
    Hide/Show Activity Home (View) Cancel button based on activity type and its owner
    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

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 > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
#ManoVerse Profile Picture

#ManoVerse 101

#2
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 66 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans