Bakersville
asked on
readystate=400 crm 2011 when retreiveing lookup from another entity
Hi everyone
I am having some issues when I am trying to collect a lookup field from one entity to put onto my newly created form.
It all works up to this.readystate. This always = 400 and I am unable to figure out why.
Please see code below
Please can anyone help.
I am having some issues when I am trying to collect a lookup field from one entity to put onto my newly created form.
It all works up to this.readystate. This always = 400 and I am unable to figure out why.
Please see code below
///<reference path="Libraries\jquery-1.4.4.js" />
///<reference path="Libraries\AjaxREST.js" />
///<reference path="Libraries\json.js" />
function SetDebtDetails() {
//Get the ID for Matter
var matterItem = Xrm.Page.getAttribute("dar_matter").getValue();
var matterID = matterItem[0].id;
//Replace{}
matterID = matterID.replace('{', '').replace('}', '');
//Get ODataPath
var oDataPath = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/organizationdata.svc";
//Construct the OData query
var filter = "/IncidentSet?" +
"$select=dar_debtdetailsmatter" +
"&$filter=dar_matter/Id eq (guid'" + matterID + "')" +
"&$orderby=dar_matter desc" +
"&$top=1";
alert(oDataPath);
alert(filter);
//Now collect information together
var retrieveRecordsReq = new XMLHttpRequest();
retrieveRecordsReq.open("GET", oDataPath + filter, true);
retrieveRecordsReq.setRequestHeader("Accept", "application/json");
retrieveRecordsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveRecordsReq.onreadystatechange = function () {
if (this.readyState == 4) {
if (this.status == 200) {
var retrievedRecords = JSON.parse(retrieveRecordsReq.responseText).d;
if(retrievedRecords.results.length > 0)
{
alert("Going to set lookup");
var DebtDetails = retrievedRecords.results[0];
SetLookup("dar_debtdetailsmatter", DebtDetails.dar_debtdetailsmatterId, DebtDetails.dar_debtdetailsmatter, "dar_debtdetailsmatter");
alert("Set lookup");
alert(DebtDetails.dar_debtdetailsmatterId);
alert(DebtDetails.dar_debtdetailsmatter);
}
}
else
{
alert(this.status);
}
}
else
{
alert(this.readyState);
}
};
retrieveRecordsReq.send();
}
Please can anyone help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi all
I have finally got over the 400 error, however, I am continually getting an undefined error when I try and break down my results back.
alert("dar_debtdetailmatte r", DebtDetails.dar_debtdetail matterId, DebtDetails.dar_Name, DebtDetails.LogicalName);
returnd
dar_debtdetailmatter, undefined, undefined, undefined
Can anyone help please as I am loosing the will
Thank you
I have finally got over the 400 error, however, I am continually getting an undefined error when I try and break down my results back.
alert("dar_debtdetailmatte
returnd
dar_debtdetailmatter, undefined, undefined, undefined
Can anyone help please as I am loosing the will
Thank you
Hi,
You should use this-
alert("dar_debtdetailmatte r" + DebtDetails.dar_debtdetail matterId + DebtDetails.dar_Name + DebtDetails.LogicalName);
The alert() method only takes 1 argument. So concatenating all the required properties.
Makes sense?
You should use this-
alert("dar_debtdetailmatte
The alert() method only takes 1 argument. So concatenating all the required properties.
Makes sense?
I don't think there is any problem in your script. However, the "may be" situation is matterID can be null. But why don't you try other ways which are easily available?!?
Try to use Xrm.Page.context.getClient
Have you tried requesting it through JQuery? Similar example is below-
Open in new window
However, I would suggest you work with https://xrmservicetoolkit.codeplex.com
The library has all the methods ready with it and you just have to call them with parameters. And the return value is the object which can be easily worked within JS.
Here is a help with all methods - http://xrmservicetoolkit.codeplex.com/wikipage?title=Rest%20Functions
Why don't you go for simple SOAP call instead? Check this- http://xrmservicetoolkit.codeplex.com/wikipage?title=Soap%20Functions