Answered by:
what's wrong with this odata query?

Question
-
Hello - I have the following odata query:
var Odata = svcPath + "/SystemUserSet?$select=SystemUserId&$filter=InternalEmailAddress eq '" + "admin@myco.com" + "'";
The intent is to retrieve the user ID by email address. However, the ajax call is returning the following error:
"No property 'InternalEmailAddress' exists in type 'Microsoft.Sdk.Entity' at position 0"
I did a quick google and people seem to think this error message indicates that something is wrong with the query. The query looks ok to me but this is my fist odata query. Here's the full function that performs the lookup and returns data:
function getAdminUserIdByEmail()
{
//Creating the Odata Endpoint
var svcPath = Xrm.Page.context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc";
var retrieveReq = new XMLHttpRequest();
var Odata = svcPath + "/SystemUserSet?$select=SystemUserId&$filter=InternalEmailAddress eq '" + "admin@myco.com" + "'";
retrieveReq.open("GET", Odata, false);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveReq.onreadystatechange = function ()
{
if (this.readyState == 4 && this.status == 200) {
alert(this.responseXML);
alert(this.responseText);
}
else
{
alert(this.responseXML);
alert(this.responseText);
}
};
retrieveReq.send();
}Monday, August 12, 2013 10:18 PM
Answers
-
- Proposed as answer by JLattimerMVP, Moderator Monday, August 12, 2013 11:04 PM
- Marked as answer by dotnetteramg123 Tuesday, August 13, 2013 8:20 PM
Monday, August 12, 2013 11:04 PMModerator
All replies
-
- Proposed as answer by JLattimerMVP, Moderator Monday, August 12, 2013 11:04 PM
- Marked as answer by dotnetteramg123 Tuesday, August 13, 2013 8:20 PM
Monday, August 12, 2013 11:04 PMModerator -
Thanks Jason! My revised query is below. The request is returning success now, but I'm having a problem accessing the data. The code below is hitting alert("Error Looking Up Template"). What mods do I need to make to this code in order to access the expected data?
function getMSRCUserId()
{
//Creating the Odata Endpoint
var svcPath = Xrm.Page.context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc";
var retrieveReq = new XMLHttpRequest();
var Odata = svcPath + "/SystemUserSet?$select=SystemUserId&$filter=InternalEMailAddress eq '" + "secure@microsoft.com" + "'";
retrieveReq.open("GET", Odata, false);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveReq.onreadystatechange = function ()
{
if (this.readyState == 4 && this.status == 200) {
var resultXml = this.responseXML;
var entityNode = resultXml.selectSingleNode("s:Envelope/s:Body/ExecuteResponse/ExecuteResult/a:Results/a:KeyValuePairOfstringanyType/c:value/a:Entities/a:Entity")
if (entityNode == null) {
alert("Error Looking Up Template");
return;
}
var attributesRoot = entityNode.selectSingleNode("a:Attributes");
var systemuserid = findNodeByValue(attributesRoot, "a:KeyValuePairOfstringanyType/c:key", "systemuserid").parentNode.lastChild.text;
alert('systemuserid = ' + systemuserid);
}
};
retrieveReq.send();
}Tuesday, August 13, 2013 8:20 PM