web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

some fetchXml can be execute in QueryString, but not exeute in $batch, error message is : 'select' and 'expand' cannot be both null or empty.

(0) ShareShare
ReportReport
Posted on by 10

I want to execute the flow fetchXml by webapi, 

<fetch version='1.0' output-format='xml-platform' mapping='logical' aggregate='true'>
<entity name = 'new_mob_notification' >
<attribute name='new_name' alias='colcount' aggregate='countcolumn'/>
<filter type ='and'>
<condition attribute = 'new_readstatus' operator= 'eq' value = '1' />
<condition attribute = 'statecode' operator= 'eq' value = '0' />
<condition attribute = 'new_receiver' operator= 'eq' value = '67781f72-450c-e611-80bc-000c292d3ec1' />
</filter>
</entity>
</fetch>

when executed by HTTP GET with QueryString , it run successfully. 

but when I run in $batch ,  crm throw the follow exception:

{"Message":"'select' and 'expand' cannot be both null or empty.","ExceptionMessage":"'select' and 'expand' cannot be both null or empty.","ExceptionType":"System.ArgumentException","StackTrace":"   在 System.Web.OData.Query.SelectExpandQueryOption..ctor(String select, String expand, ODataQueryContext context, ODataQueryOptionParser queryOptionParser)\r\n   在 Microsoft.Crm.Extensibility.OData.CrmODataEntityTypeSerializer.CreateSelectExpandNode(EntityInstanceContext entityInstanceContext)\r\n   在 System.Web.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteEntry(Object graph, ODataWriter writer, ODataSerializerContext writeContext, IEdmTypeReference expectedType)\r\n   在 System.Web.OData.Formatter.Serialization.ODataFeedSerializer.WriteFeed(IEnumerable enumerable, IEdmTypeReference feedType, ODataWriter writer, ODataSerializerContext writeContext)\r\n   在 System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content, HttpContentHeaders contentHeaders)\r\n   在 System.Web.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- 引发异常的上一位置中堆栈跟踪的末尾 ---\r\n   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   在 System.Web.OData.Batch.ODataBatchResponseItem.<WriteMessageAsync>d__0.MoveNext()\r\n--- 引发异常的上一位置中堆栈跟踪的末尾 ---\r\n   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   在 System.Web.OData.Batch.ODataBatchContent.<SerializeToStreamAsync>d__0.MoveNext()\r\n--- 引发异常的上一位置中堆栈跟踪的末尾 ---\r\n   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   在 System.Web.Http.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__1b.MoveNext()","ErrorCode":500}

the full http request is :

------------------------------------------------------------------------------------------------------------

POST crm2.recloud.cc/.../v8.2$batch HTTP/1.1
Authorization: Bearer *********
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
Prefer: odata.include-annotations="*"
MSCRMCallerID: 67781f72-450c-e611-80bc-000c292d3ec1
Content-Type: multipart/mixed; boundary="batch__boundary_cd52b5621bd64456ad73a33add6c0021"
Host: crm2.recloud.cc:4431
Content-Length: 918
Expect: 100-continue
Accept-Encoding: gzip, deflate

--batch__boundary_cd52b5621bd64456ad73a33add6c0021
Content-Type: application/http
Content-Transfer-Encoding: binary

GET /org1/api/data/v8.2/new_mob_notifications?fetchXml=%3Cfetch+version%3D%271.0%27+output-format%3D%27xml-platform%27+mapping%3D%27logical%27+aggregate%3D%27true%27%3E%3Centity+name+%3D+%27new_mob_notification%27+%3E%3Cattribute+name%3D%27new_name%27+alias%3D%27colcount%27+aggregate%3D%27countcolumn%27%2F%3E%3Cfilter+type+%3D%27and%27%3E%3Ccondition+attribute+%3D+%27new_readstatus%27+operator%3D+%27eq%27+value+%3D+%271%27+%2F%3E%3Ccondition+attribute+%3D+%27statecode%27+operator%3D+%27eq%27+value+%3D+%270%27+%2F%3E%3Ccondition+attribute+%3D+%27new_receiver%27+operator%3D+%27eq%27+value+%3D+%2767781f72-450c-e611-80bc-000c292d3ec1%27+%2F%3E%3C%2Ffilter%3E%3C%2Fentity%3E%3C%2Ffetch%3E HTTP/1.1
Host: crm2.recloud.cc:4431


--batch__boundary_cd52b5621bd64456ad73a33add6c0021--

------------------------------------------------------------------------------------------------------------

my crm version : dynamics 365, v8.2

??

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    In FetchXML query you should have at least one attribute from entity which is not null to resolve this issue like Id.

    <attribute name='new_mob_notificationid' />

    if that works mark as verified.

    Thank you,

    Dhruv.

    Microsoft Certified Professional

  • liubiaoyong Profile Picture
    10 on at

    Dear Dhruv, thank you !

    I know this can work.

    If I add a linkedEntity for filter and no columns selected with any aggregate, the same error occurred too. I think Microsoft should update the $batch endpoint to execute in same rule.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans