Skip to main content

Notifications

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

News and Announcements

Announcing Category Subscriptions!

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans