Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to check if Logged-in User is in a Team or not.?

(0) ShareShare
ReportReport
Posted on by

I have a button APPROVE in Deal Entity. And a subgrid named TEAMMEMBERS in Deal Entity.

On Load of Form i need to check if the logged in user is in Team or not and then show/hide that button. How can i achieve this through Webapi..

*This post is locked for comments

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: How to check if Logged-in User is in a Team or not.?

    Hi,

    You can use the JS code below with the $expand in Web API and register this function in Custom Javascript enable rule of the button.

    function IsTeamMember() {
        var currentLoggedInUserId = Xrm.Page.context.getUserId().replace("{", "").replace("}","");
        var teamId = "06f352df-1db9-e811-a968-000d3af27cc7"; //Replace with the your Team ID
        var req = new XMLHttpRequest();
        req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/teams(" + teamId + ")?$expand=teammembership_association($filter=systemuserid eq " + currentLoggedInUserId + ")", false);
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
        req.setRequestHeader("Prefer", "odata.maxpagesize=10");
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
                    debugger;
                    var results = JSON.parse(this.response);
                    if (results.teammembership_association.length > 0)
                        return true;
                    else
                        return false;
                }
                else {
                    alert(this.statusText);
                }
            }
        };
        req.send();
    }

    Hope this helps.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: How to check if Logged-in User is in a Team or not.?

    Hi,

    Please use CRM Rest Builder to build the WEB API request. This is the easiest way to build the query as well as execute it and see the results.

    carldesouza.com/dynamics-crm-rest-builder

    You can download the tool here- github.com/.../releases

    Hope this helps.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: How to check if Logged-in User is in a Team or not.?

    Hi,

    Try with this -

    function checkTeam() {

    var result = true;

    var teamName = 'System Administrator';

    var clientURL = Xrm.Page.context.getClientUrl();

    var req = new XMLHttpRequest();

    var userId = Xrm.Page.context.getUserId().substr(1, 36);

    var query = "/api/data/v8.2/systemusers(" + userId + ")?$expand=teammembership_association($select=name;$filter=name eq '" + teamName + "')";

    req.open("GET", encodeURI(clientURL + query), false);  

    req.setRequestHeader("Accept", "application/json");

    req.setRequestHeader("Content-Type", "application/json;charset=utf-8");

    req.setRequestHeader("OData-MaxVersion", "4.0");

    req.setRequestHeader("OData-Version", "4.0");

    req.send();

    if (req.status == 200) {

    var data = JSON.parse(req.response).teammembership_association;

    if (data.length > 0)

    {

    result = true;

    return result;

    } else {

    result = false;

    return result;

    }

    };

    return result;

    }

  • Suggested answer
    Dynamics365 Rocker Profile Picture
    7,755 on at
    RE: How to check if Logged-in User is in a Team or not.?

    There is N:N relationship between team and users. Below link may help you to achieve your task.

    community.dynamics.com/.../checking-if-a-user-is-a-member-of-a-team-using-javascript

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 Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans