Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

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

Posted on by 353
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

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

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans