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
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
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();
}
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.
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))
chech here, its 9.1
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.
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.
I HAVE SAME ERROR, POTENTIAL THREAT MY VERSION IS 9.1....
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)
// 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();
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" xmlns="schemas.microsoft.com/.../Contracts">
↵ <ActivityId>19e1bdb8-b6ed-42ae-a0a3-2f4a6391a333</ActivityId>
↵ <ErrorCode>-2147220970</ErrorCode>
↵ <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
↵ <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>
André Arnaud de Cal...
292,516
Super User 2025 Season 1
Martin Dráb
231,409
Most Valuable Professional
nmaenpaa
101,156