Skip to main content

Notifications

Announcements

No record found.

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.

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

  • liubiaoyong Profile Picture
    liubiaoyong 10 on at
    RE: some fetchXml can be execute in QueryString, but not exeute in $batch, error message is : 'select' and 'expand' cannot be both null or empty.

    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.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: some fetchXml can be execute in QueryString, but not exeute in $batch, error message is : 'select' and 'expand' cannot be both null or empty.

    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

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans