web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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

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
Martin Dráb Profile Picture

Martin Dráb 46 Most Valuable Professional

#2
Pallavi Phade Profile Picture

Pallavi Phade 33

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 28 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans