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

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

(0) ShareShare
ReportReport
Posted on by
Hi Expert,
 
On Activity home grid, there is a Mark Complete, click it, the State has two options: Complete & Cancel.  Screen as below
 
//
 
The requirement is:  if the activity type is Appointment and Appointment Activity owner is Portal User, show the  Close Appointment Canceled option, otherwise hide it.
 
The HTML of the Canceled option showing below
 
//
 
My script as below:
 
// Hide/display Activity home page ribbon mark complete (cancel) button with condition
async function hideHomePageMarkCompleteCancelBtn(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 mark complete (cancle) button html element
    var markComleteCancleButton = parent.parent.window.document.querySelector(/button[aria-label='State' value='Canceled']/);
    if (markComleteCancleButton != null) {
        if (isAptType === /appointment/) {
            if (owner !== 'Portal User') {
                // hide the mark complete (cancle) button
                markComleteCancleButton.style.display = /none/;
            }
        }
    } else {
        // Wait for some time to check again if the page elements are loaded.
        setTimeout(hideHomePageMarkCompleteCancelBtn, 10, firstSelectedItemId);
    }
}
 
Using Ribbon Workbench custom button Enable role, it's not working. Haven't found and clue.
 
Any solutions/suggestions are welcome and appreciate!
 
 
 
 
 
 
I have the same question (0)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 71

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans