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 find the current user existing teams dynamically using js.

(0) ShareShare
ReportReport
Posted on by 165

hw to find the current user existing teams dynamically using js.,

i could not find relation in rest builder between user and team.

*This post is locked for comments

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: how to find the current user existing teams dynamically using js.

    Hi Shahzeb,

    sorry for not getting back to you on this. below code should work :

    function GetUserTeams()

    {

    var userSettings = Xrm.Utility.getGlobalContext().userSettings; // userSettings is an object with user information.

       var current_User_Id = userSettings.userId; // The user's unique id

       var newid = current_User_Id.slice(1, -1);

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/teams?$select=name&$expand=teammembership_association($filter=systemuserid eq "+newid+")", true);

    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=\"*\"");

    req.onreadystatechange = function() {

       if (this.readyState === 4) {

           req.onreadystatechange = null;

           if (this.status === 200) {

               var results = JSON.parse(this.response);

               for (var i = 0; i < results.value.length; i++) {

                   var name = results.value[i]["name"];

                   alert(name);

               }

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

    }

  • Shahzeb Khan Profile Picture
    Shahzeb Khan 165 on at
    RE: how to find the current user existing teams dynamically using js.

    orgurl.api/data/v9.1/teams$select=name&$expand=teammembership_association($filter=systemuserid eq 6238BD53-8B02-E911-B972-000D371A4385)

    i entered this, and i have same error.

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: how to find the current user existing teams dynamically using js.

    Okay thanks for confirming

    can you please check if you are able to browse the url

    yourorgname.api.crm8.dynamics.com/api/data/v9.1/teams$select=name&$expand=teammembership_association($filter=systemuserid eq (userguid))    

  • Shahzeb Khan Profile Picture
    Shahzeb Khan 165 on at
    RE: how to find the current user existing teams dynamically using js.

    155808.Capture.PNGchech here, its 9.1

  • Shahzeb Khan Profile Picture
    Shahzeb Khan 165 on at
    RE: how to find the current user existing teams dynamically using js.

    CAN WE GENERATE SUCH URL FUNCTIONALLY IN MS CRM ENVIRONMENT TO CHECK WHAT URL WE HAVE AND WHAT WE GETTING IN THE CODE TO DETECT THE ERROR.

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: how to find the current user existing teams dynamically using js.

    what is your dynamics crm version? if its 2016 it cannot be 9.1.

    please go to settings > customiztion> developer resources and get the api url from there.

  • Shahzeb Khan Profile Picture
    Shahzeb Khan 165 on at
    RE: how to find the current user existing teams dynamically using js.

    I HAVE SAME ERROR, POTENTIAL THREAT MY VERSION IS 9.1....

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: how to find the current user existing teams dynamically using js.

    Did you try to browse the url as i suggested to see if you get response in the browser?

    Also - change the request type from ‘false’ to ‘true’ in the get request ( in the end of the line)

  • Shahzeb Khan Profile Picture
    Shahzeb Khan 165 on at
    RE: how to find the current user existing teams dynamically using js.

    // MY CODE, IS THERE SOMETHING WRONG, MY VERSION IS 9.1

              var loggedInUserId = Xrm.Page.context.getUserId();

              loggedInUserId = loggedInUserId.replace('{', '').replace('}', '');

              var req = new XMLHttpRequest();

    var globalContext = Xrm.Utility.getGlobalContext();

    var uri=globalContext.getClientUrl();

              req.open("GET", uri + "/api/data/v9.1/teams$select=name&$expand=teammembership_association($filter=systemuserid eq "+loggedInUserId+")",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.onreadystatechange = function() {

                  if (this.readyState === 4) {

                      req.onreadystatechange = null;

                      if (this.status === 200) {

                          var results = JSON.parse(this.response);

                          // I have not tried you can debug results part

                          for (var i = 0; i < results.value.length; i++) {

                              var teamname = results.value[i]["name"];

                          }

                      } else {

                          Xrm.Utility.alertDialog(this.statusText);

                      }

                  }

              };

              req.send();

  • Shahzeb Khan Profile Picture
    Shahzeb Khan 165 on at
    RE: how to find the current user existing teams dynamically using js.

    Please check:

    _error:

    Code: null

    Description: "A potentially dangerous Request.Path value was detected from the client (&)."

    DisplayText: ""

    ErrorCode: 0

    RedirectToEdit: false

    SerializedEntity: null

    SerializedException: "Unhandled exception: ↵Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]↵Message: System.Web.HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (&).

    ↵   at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()

    ↵   at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context): Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #0D42283BDetail:

    ↵<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance&quot; xmlns="schemas.microsoft.com/.../Contracts&quot;>

    ↵  <ActivityId>19e1bdb8-b6ed-42ae-a0a3-2f4a6391a333</ActivityId>

    ↵  <ErrorCode>-2147220970</ErrorCode>

    ↵  <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic&quot; />

    ↵  <Message>System.Web.HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (&).

    ↵   at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()

    ↵   at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context): Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #0D42283B</Message>

    ↵  <Timestamp>2019-01-21T09:59:02.43359Z</Timestamp>

    ↵  <ExceptionRetriable>false</ExceptionRetriable>

    ↵  <ExceptionSource i:nil="true" />

    ↵  <InnerFault i:nil="true" />

    ↵  <OriginalException i:nil="true" />

    ↵  <TraceText i:nil="true" />

    ↵</OrganizationServiceFault>

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

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... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans