I am struck here badly, Have been trying different options but no use.
I have two entities and have to create an association between these two.
I have the following code to achieve this.
var clientURL = parent.Xrm.Page.context.getClientUrl();
var req = new XMLHttpRequest()
req.open("POST", encodeURI(clientURL + "/api/data/v8.0/new_experiencetopgs"), true);
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.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 204) {
var accountUri = this.getResponseHeader("OData-EntityId");
}
else {
var error = JSON.parse(this.response).error;
}
}
};
var experiencetopgs = new Object();
//String Field
experiencetopgs.new_name = Math.random()+"ExperienceGroup";
var experienceId =parent.Xrm.Page.data.entity.getId().substring(1, 37);
//Lookup
experiencetopgs["new_exppgexperience@odata.bind"] = "/***_experiences("+experienceId+")"
experiencetopgs["new_exppracticegroup@odata.bind"] = "/new_experiencetopgs("+practiceGroupId+")"
jObj=JSON.stringify(experiencetopgs).replace(/ /g,'');
var response = req.send(jObj);
When it comes to ***_experiences, it's not accessible, I tried to directly access this entity using web API URL.
server/.../v8.0***_experienceses
Response :
{
"error":{
"code":"","message":"Resource not found for the segment '***_experienceses'.",
"innererror":{
"message":"Resource not found for the segment '***_experienceses'.",
"type":"Microsoft.OData.Core.UriParser.ODataUnrecognizedPathException",
"stacktrace":"at Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.ParsePath(ICollection`1 segments)\r\n at Microsoft.OData.Core.UriParser.Parsers.ODataPathFactory.BindPath(ICollection`1 segments, ODataUriParserConfiguration configuration)\r\n at Microsoft.OData.Core.UriParser.ODataUriParser.Initialize()\r\n at System.Web.OData.Routing.DefaultODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath, ODataUriResolverSetttings resolverSettings, Boolean enableUriTemplateParsing)\r\n at System.Web.OData.Routing.DefaultODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataPathHandler.Parse(IEdmModel model, String serviceRoot, String odataPath)"
}
}
}