I'm trying to write a jQuery query for CRM 2013. It is called from the onLoad of the Enquiry form - I need to get all Customer Quotes with that Enquiry's id. I'm a totaly beginner when it comes to oData, so the code below is from examples I've found online. I can't get past the if statement that checks for status == 200. I only see the alerts up as far as "Here 2".
My oDataPath is fine - I put it into a browser and I got xml back, which looks fine, so I presume it could be something with my filter? I want to get back the vendor Id column from the Customer Quote entity, where the Enquiry id on the Customer Quote equals the id of the current Enquiry record I'm looking at. There's a 1:M relationship between Enquiry and Customer Quote.
I'd appreciate any help with this! Remember, I'm not very knowledgeable in this area!
Thanks.
function QueryCustomerQuotes () { alert("In QueryCustomerQuotes"); var enquiryId =Xrm.Page.data.entity.getId(); enquiryId = enquiryId .replace('{', '').replace('}', ''); alert("enquiryId: " + enquiryId); var oDataPath = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/organizationdata.svc"; alert("oDataPath: " + oDataPath); var filter = "/new_customerquoteSet?" +"$select=new_vendorid" + "&$filter=new_enquiryid/Id eq (guid'" + enquiryId + "')"; alert("filter: " + filter); 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 () { alert("Here 1"); if (this.readyState == 4) { alert("Here 2"); if (this.status == 200) { alert("Here 3"); var retrievedRecords = JSON.parse(retrieveRecordsReq.responseText).d; if(retrievedRecords.results.length > 0) { var vendorIds = retrievedRecords.results; alert("vendorIds[0]: " + vendorIds[0]); } } } }; retrieveRecordsReq.send(); }