Hello All,
I have some business logic in Java script which was using soap response.
SOAP response for FetchXML returns parameter Type. So we have written the logic to get the data from response
1. For Optionset type of parameter from Formatted values
2. For string, int, bool, money Type of parameter get the data from Value
3. For Entity Reference from ID field.
But now we are changing our all soap call to Rest calls. Web API does not return the Type of the parameter along with the response. So I could not identify if the parameter is of type Option set or other field type.
I am using Fetch XML in Web Api request, below is the code and XMLHTTPHeaders sample that I am using.
var req = new XMLHttpRequest(); req.open("GET", odataEndpoint + entityPuralName + "?fetchXml=" + encodedFetchXML, 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.setRequestHeader("Prefer", "odata.include-annotations=\"*\""); req.onreadystatechange = function () { if (this.readyState === 4) { req.onreadystatechange = null; //success if (this.status === 200) { results = JSON.parse(this.response); } //failure else { var error = JSON.parse(this.response).error; errorHandler(error); } }; };
Fetch XML Used in SOAP as well as WebAPI request :
<fetchversion='1.0'output-format='xml-platform'mapping='logical'><entityname='opportunity'><all-attributes/><filtertype='and'><conditionattribute='opportunityid'operator='eq'value='C60E0283-5BF2-E311-945F-6C3BE5A8DD64'/></filter><link-entityname="account"from="accountid"to="parentaccountid"attributes=""alias="parentaccountid"link-type="outer"><all-attributes/></link-entity><link-entityname="transactioncurrency"from="transactioncurrencyid"to="transactioncurrencyid"alias="transactioncurrencyid"link-type="outer"><all-attributes/></link-entity></entity></fetch>
Please let me know if i am missing any request parameter while building web api request to pull Type of parameter along with response.