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!
 
 
 
 
 
 

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,123 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,895 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans