Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Web Api batch mode not returning all columns for fetchxml query

Posted on by Microsoft Employee

I'm having a problem with Web Api batch requests that I need to use because of long URLs: If I make a query using normal Web Api mode:

https://XXXXXX.crm4.dynamics.com/api/data/v8.2/accounts?fetchXml=%3Cfetch%3E%20%20%3Centity%20name%3D%27account%27%3E%20%20%20%20%3Cattribute%20name%3D%27industrycode%27%20/%3E%20%20%20%20%3Cattribute%20name%3D%27name%27%20/%3E%20%20%3C/entity%3E%3C/fetch%3E

then both name and industrycode (option set) for accounts are returned. However, if I make this a batch request:

Request URL: https://XXXXXXX.crm4.dynamics.com/api/data/v8.2/$batch

Request Method: POST

--batch_AAA123 Content-Type: application/http Content-Transfer-Encoding:binary GET xxxxxxcrm4.dynamics.com/.../accounts HTTP/1.1

Authorization: Bearer XXXX

Accept: application/json

--batch_AAA123--

then only account name is returned and not the industrycode. How can I get the industrycode returned in batch mode? Is this a bug or a limitation in Web Api or am I just doing it wrong?

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Web Api batch mode not returning all columns for fetchxml query

    This worked for me just fine:

    --batch_AAA123

    Content-Type: application/http

    Content-Transfer-Encoding:binary

    GET treecatoct2017.crm3.dynamics.com/.../accounts HTTP/1.1

    Authorization: Bearer XXXX

    Accept: application/json

    --batch_AAA123--

  • JakeH Profile Picture
    JakeH on at
    RE: Web Api batch mode not returning all columns for fetchxml query

    I'm noticing this issue with Dynamics 8.2. This does not happen in Dynamics 8.1. Changing the request body URL and the request URL itself does not help.

    Considering I have an entity with two fields: attributeA and attributeB.

    I have two records in the system.

    Record 1:
    attributeA: null
    attributeB: Hello World
    createdon: 1999-09-09T00:00:00

    Record 2:
    attributeA: 5000
    attributeB: Foo bar
    createdon: 2049-09-09T00:00:00

    The following will return Record 2 first, with both attributes on Record 2 and only attributeB on Record 1.

    curl -X POST \
      'org.reg.dynamics.com/.../v8.1$batch' \
      -H 'content-type: multipart/mixed;boundary=batch_fetchxml' \
      -d '--batch_fetchxml
    Content-Type: application/http
    Content-Transfer-Encoding: binary
    
    GET org.reg.dynamics.com/.../entity;fetch><entity name="entity"><attribute name="attributeA"/><attribute name="attributeB"/><order attribute="createdon" descending="true" /></entity></fetch> HTTP/1.1
    Content-Type: application/json; charset=utf-8
    OData-Version: 4.0
    OData-MaxVersion: 4.0
    
    --batch_fetchxml--'

    However, changing the order's descending attribute to false will return Record 1 first, and neither record will have attributeA.

    It seems that the return is being shaped by the contents of the first record -- if the first record doesn't contain all desired attributes, then subsequent siblings will not contain those attributes regardless of the record's data.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans