web
You’re offline. This is a read only version of the page.
close
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 167

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

I have the same question (0)
  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    Hi Shahzeb,

    use retrieve multiple - in the search entity say "teams" and then select from N:N relationship "teammembership_association" and filtering attribute select Systemuserid. It would like somethin like below:

        function GetTeams()

           {

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

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

               var req = new XMLHttpRequest();

               req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/teams$select=name&$expand=teammembership_association($filter=systemuserid eq "+loggedInUserId+")",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.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
    167 on at

    Thanx Ravish, I have been trying this, but i m getting error in response and when i hover my cursor on loggedinuserid, i dont see my id which was actually there before entering into response.

  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    Okay , try this:

    var lookup= Xrm.Page.getAttribute(“fieldname”).getValue();  

    var newid = lookup[0].id.slice(1, -1);

    then use the newid in the search.

  • Shahzeb Khan Profile Picture
    167 on at

    i'm geting id of current user all good, but in response i get error.

  • Rawish Kumar Profile Picture
    13,758 on at

    what error are you getting?

  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    when i am browsing this in my trial i am getting team associated to my user . not sure why its not working on your environment :

    passion4dynamicscrm.api.crm8.dynamics.com/.../teams$select=name&$expand=teammembership_association($filter=systemuserid eq 2024F380A7-5174-4465-A945-185A2AC7B7CE)    

    you can try to browse the same by changing url and guid of the user. Make sure you are using the correct api version such as 8.1 or 8.2.

  • Shahzeb Khan Profile Picture
    167 on at

    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>

  • Shahzeb Khan Profile Picture
    167 on at

    // 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();

  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    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
    167 on at

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

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans