1

Having trouble figuring how to get results from the following fetchXml using the new retrieveMultipleRecords (Client API reference):

var request = "<fetch output-format='xml-platform' distinct='true' version='1.0' mapping='logical'>" +
"<entity name='msdyn_incidenttype'>" +
"<attribute name='msdyn_name'/>" +
"<attribute name='createdon'/>" +
"<attribute name='msdyn_estimatedduration'/>" +
"<attribute name='msdyn_incidenttypeid'/>" +
"<order attribute='msdyn_name' descending='false'/>" +
"<link-entity name='product' link-type='inner' alias='ag' from='productid' to='aka_productfamilyid'>" +
"<link-entity name='msdyn_customerasset' link-type='inner' alias='ah' from='msdyn_product' to='productid'>" +
"<filter type='and'>" +
"<condition attribute='msdyn_customerassetid' operator='eq' uiname='' uitype='msdyn_customerasset' value='${custAssetId}'/>" +
"</filter>" +
"</link-entity>" +
"</link-entity>" +
"</entity>" +
"</fetch>";

I use the above fetchXml with the new client api reference as follows:

var results = Xrm.WebApi.retrieveMultipleRecords("msdyn_incidenttype",request).then(
  function success(result) {
      for (var i = 0; i < result.entities.length; i++) {
          console.log(result.entities[i]);
      }
      console.log("Next page link: " + result.nextLink);
      // perform additional operations on retrieved records
  },
  function (error) {
      console.log(error.message);
      // handle error conditions
  }

The document I read (https://learn.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/xrm-webapi/retrievemultiplerecords) states that the second parameter are options and if is fetchXml (as I am using) then to specify it there. However Im receiving the following errors in console:

HTTP400: BAD REQUEST - The request could not be processed by the server due to invalid syntax. (XHR)GET - https://dev.crm.dynamics.com/api/data/v9.0/msdyn_incidenttypes?fetch output-format='xml-platform' distinct='true' version='1.0' mapping='logical'>entity name='msdyn_incidenttype'>attribute name='msdyn_name'/>attribute name='createdon'/>attribute name='msdyn_estimatedduration'/>attribute name='msdyn_incidenttypeid'/>order attribute='msdyn_name' descending='false'/>link-entity name='product' link-type='inner' alias='ag' from='productid' to='aka_productfamilyid'>link-entity name='msdyn_customerasset' link-type='inner' alias='ah' from='msdyn_product' to='productid'>filter type='and'>condition attribute='msdyn_customerassetid' operator='eq' uiname='' uitype='msdyn_customerasset' value='${custAssetId}'/>/filter>/link-entity>/link-entity>/entity>/fetch>

Am I missing something here?

1 Answer 1

1

You should add "?fetchXml=" in front like below:

Xrm.WebApi.retrieveMultipleRecords("msdyn_incidenttype", "?fetchXml= " + request).then(
                function success(result) {
                    return result;
                },
                function (error) {
                    console.log("failed with error: ", error);
                    return null;
                }
            );

options
OData system query options or FetchXML query to retrieve your data.

  • Following system query options are supported: $select, $top, $filter, $expand, and $orderby.

  • To specify a FetchXML query, use the fetchXml attribute to specify the query.

Reference

Sign up to request clarification or add additional context in comments.

1 Comment

Yup. Just found it as I seen your answer. I used the following: var request = "?fetchXml=" + encodeURIComponent(request);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.