On Activity home grid, there is a Mark Complete, click it, the State has two options: Complete & Cancel. Screen as 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!