Skip to main content

Notifications

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?
  • Verified answer
    Dengliang Li Profile Picture
    Microsoft Employee on at
    Hide/Show Appointment Close button based on owner
    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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

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,323 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,193 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans