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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Liquid - count the results returned by fetchxml

(0) ShareShare
ReportReport
Posted on by

I need to count the results returned by fetch xml in liquid and if 0 records are returned then need to execute a javascript code, How can i do this?

I have the same question (0)
  • Tilan Bethmage Profile Picture
    on at
    RE: Liquid - count the results returned by fetchxml

    it worked

  • Verified answer
    oliver.rodrigues Profile Picture
    4,052 on at
    RE: Liquid - count the results returned by fetchxml

    hi Tilan, did the above work for you?

  • Tilan Bethmage Profile Picture
    on at
    RE: Liquid - count the results returned by fetchxml

    Hi Oliver,

    When i add the if statement it becomeslike {% if fetchResult.size  "& g t; "   0 %}

    with & and gt so its not working, not sure why

  • Suggested answer
    oliver.rodrigues Profile Picture
    4,052 on at
    RE: Liquid - count the results returned by fetchxml

    hi, you can remove the hyphen "-" from the liquid tags, although I don't think that's the problem

    is the issue when you are copying the code? have you tried just re-write it?

    did you add a "div" with any content inside the IF just to see if it is hitting that point?

  • Tilan Bethmage Profile Picture
    on at
    RE: Liquid - count the results returned by fetchxml
    [deleted]
  • SOUNDHARYA.N.V Profile Picture
    165 on at
    RE: Liquid - count the results returned by fetchxml

    Hi,

    Try this,

    {% fetchxml myFetch %}
    <fetch version="1.0" mapping="logical">
    <entity name="name">
    <attribute name="name" />
    <attribute name="name" />
    <attribute name="createdon" />
    <order attribute="name" descending="false" />
    </entity>
    </fetch>
    {% endfetchxml %}

    {% if myFetch.results.entities.size > 0 %}

    // perform your logic here

    {% endif %}

    if you want to use in Javascript if condition then assign the results and use below code

    {% assign result = myFetch.results.entities %}

    <script>
    if(result.size > 0)
    {
    // perform your logic here
    }
    </script>

    Please mark as verified if the answer is helpful. 

  • Suggested answer
    oliver.rodrigues Profile Picture
    4,052 on at
    RE: Liquid - count the results returned by fetchxml

    hi Tilan

    you should be able to get your result count with no issues using liquid/fetch

                          {%- fetchxml myFetch -%}

                           <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">

                               <entity name="xxxxxx">

                                   <attribute name="xxxx" />

                               </entity>

                           </fetch>

                           {%- endfetchxml -%}

                           {%- assign fetchResult = myFetch.results.entities -%}

                           {%- if fetchResult.size > 0 -%}

                           {% endif %}

  • Fabio Branco Profile Picture
    on at
    RE: Liquid - count the results returned by fetchxml

    Hello Tilan,

    Thank you for your question

    You should be able to count the total elements of the response from the Collection.

    The following community thread has directions with the steps to count the results from the QueryExpression:

    Allow me to share aditional documentation with th steps to count the records of the Collection from the WEB API:

    Does this information answer your question? 

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 258

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 164

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 121 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans