Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Retrieve Owning User Teams using JS

Posted on by 595

Hi All,

I have An requirement that I need to hide and show buttons based on teams of Current Users.

How to retrieve User Trams Using Javascript?

Please help me to achieve this requirement...

  • Suggested answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: Retrieve Owning User Teams using JS

    Hi, 

    var currentUserId = Xrm.Utility.getGlobalContext().userSettings.userId;
    Xrm.WebApi.retrieveMultipleRecords('team', "?$select=name,_businessunitid_value,teamtype&$expand=teammembership_association($filter=(systemuserid eq " currentUserId "))&$filter=(teammembership_association/any(o1:(o1/systemuserid eq " currentUserId ")))").then(
        function success(result) {
            console.log(result)
        },
        function (error) {
            console.log(error.message);
            // handle error conditions
        }
    );
    
    

    Manage Button visibility is tricky when you perform an async operation. Take a look to this greate example shared by Andrew: 

    https://butenko.pro/2018/11/13/showing-ribbon-button-based-on-the-result-of-async-operation/

    Good Luck

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans