XRM-OSS / Xrm-WebApi-Client

A promise-based JavaScript library for the Microsoft Dynamics CRM WebApi - TypeScript type definitions available
https://xrm-oss.github.io/Xrm-WebApi-Client/
MIT License
100 stars 28 forks source link

Retrieve by FetchXml weird beheviour #33

Closed garciasa closed 6 years ago

garciasa commented 6 years ago

Hi there, I get a weird behavior fetching data via fetchxml.

export const getFrequencies = mpid => {
  const request = {
    entityName: 'wfd_monitoringprogrammefrequency',
    fetchXml: `<fetch mapping="logical" >
                  <entity name="wfd_monitoringprogrammefrequency" >
                      <attribute name="wfd_monitoringprogrammefrequencyid" />
                      <attribute name="wfd_samplingperiod" />
                      <attribute name="wfd_year1frequency" />
                      <attribute name="wfd_year2frequency" />
                      <attribute name="wfd_year3frequency" />
                      <attribute name="wfd_additionaldescriptor" />
                      <filter type="and" >
                          <condition attribute="wfd_monitoringprogrammeid" operator="eq" value="${mpid}" />
                      </filter>
                      <link-entity name="wfd_statusdefinition" to="wfd_qualityelementid" from="wfd_statusdefinitionid" alias="c" >
                          <attribute name="wfd_code" />
                          <attribute name="wfd_name" />
                      </link-entity>
                  </entity>
                </fetch>`,
  };

  return WebApiClient.Retrieve(request);
};

if the first field of the query (in this case wfd_samplingperiod) doesn't have data, the others records in the response, even if they have data, don't have that key present in the object. If the first element returning by the fetch has data for that key, then that key is correctly populated for the rest of the elements (if it has data comes with data, and if not present the key is no present in the object)

same fetchxml in Xrmtoolbox always works as expected...

Am I doing something wrong?

Regards, Antonio

DigitalFlow commented 6 years ago

Hi @garciasa,

Can you open your browser debugging tools while executing the request and check the response inside the Network tab of your debugger? You should be able to check the returned results in plain text there. This allows you to check, whether the response contains your results and my library is doing something wrong, or if the CRM is behaving weird.

You can also try sending the query as query params. There you can check whether this behavior still occurs. Example: WebApiClient.Retrieve({entityName: "wfd_monitoringprogrammefrequency", queryParams: `?$select=wfdsamplingperiod,wfd_year1frequqency&$filter=_wfd_monitoringprogrammeid_value eq ${mpid}&$expand=wfd_qualityelementid($select=wfd_code,wfd_name)`})

You can check above example, it might be that the mpid needs single quotes in the filter (don't remember right now) and the expand property needs to be with your exact schema name, so you might need to adjust some chars to uppercase.

Kind Regards, Florian

garciasa commented 6 years ago

Hi Florian, in the network tab, the behavior is the same, those elements are not populated if the first element is blank..

It's working as expected if we use the query as query params. So I'm guessing something funny is happening when we use the fetchxml way.

Cheers,

DigitalFlow commented 6 years ago

Hi Antonio,

glad that it works at least using query params. Yes, it seems like the behavior is caused by the CRM in that case. I'll close this issue.

Kind Regards, Florian