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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Hide/Show Appointment Close button based on owner

(0) ShareShare
ReportReport
Posted on by 102
Hi Experts,
 
The requirement is if the current user same as the owner of Appointment record, display the /Close Appointment/ ribbon button, other wise hide it. 
 
I used Enable Rule to achieve and JS code as blow:
 
// Hide/display Appointment ribbon close button with condition
function hideAppointmentCloseBtn(primaryControl) {
    debugger;
    var executionContext = primaryControl;
    var formContext = executionContext.getFormContext();
    var userSettings = Xrm.Utility.getGlobalContext().userSettings; // userSettings is an object with user information.
    var currentUserName = userSettings.userName; // The user's name
    var appointmentId = formContext.data.entity.getId().replace(/{/, //).replace(/}/, //);
    Xrm.WebApi.retrieveRecord(/appointment/, /appointmentId/, /?$expand=owninguser($select=fullname/).then(
        function success(result) {
            const owner = result.owninguser.fullname
            if (owner === currentUserName) {
                return true;
            } else {
                return false;
            }
        },
        function(error) {
            console.log(error.message);
            // handle error conditions
        }
    );
}
 
Tried million of time, It was not working. Am I missing something? Could you please advice?
I have the same question (0)
  • Verified answer
    Dengliang Li Profile Picture
    Microsoft Employee on at
    Hi,
     
    According to the Microsoft documentation.
    The primaryControl parameter value passes the form context value.
    You could just write it like this: 

    Then this line of your code:
    The appointmentId cannot be included in double quotes, it is a variable.
    A closing bracket is missing after fullname".
     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more.
    If you have further questions, please feel free to contact me .
     
    Best Regards,
    Dengliang Li
     

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…

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
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 72 Super User 2026 Season 1

#2
BillurSamdancioglu Profile Picture

BillurSamdancioglu 64 Most Valuable Professional

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans