Skip to main content

Notifications

Dynamics 365 general forum
Answered

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

Posted on by 353
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!
 
  • Verified answer
    Dengliang Li Profile Picture
    Dengliang Li 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
     
  • Suggested answer
    SidKicksin Profile Picture
    SidKicksin 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!

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,469 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans