Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Liquid: How to handle null in result of fetchXML

(0) ShareShare
ReportReport
Posted on by 25
{% fetchxml my_query %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" returntotalrecordcount="true">
.....
.....
<filter type="and">
        <condition attribute="asc_id" operator="eq" uitype="new_uitype" value="{{request.params.id}}" />
      </filter>
    </link-entity>
  </entity>
</fetch>

I am using fetchXML with liquid in web template for ADX portal. The code below works fine when I provide valid ID

{% if my_query.results.entities %}
  {{ my_query.results.entities.size }}
{% else %}
  <span class="alert">No session found for this booking</span>
{% endif %}

However, when ID is not in CRM i.e. null result I am getting this error 

Liquid error: Exception has been thrown by the target of an invocation.


Could you please tell me how to handle null result in Liquid with fetchXML. I have tried following options

{% if my_query.results.entities %}
{% if my_query.results.total_record_count %}
{% if my_query.results %}

all return same error

*This post is locked for comments

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Liquid: How to handle null in result of fetchXML

    Hi,

    As mentioned above I don't think it is not about liquid not handling null. Its is about the value in the id …So for example, if you are using the request.params.id in the fetch xml filter criteria which will accept guid. Now if you pass non guid then the fetch xml itself will throw an error. This will happens outside of liquid as well if you try it in C# code.

    Hope this helps.

  • Usmani Profile Picture
    25 on at
    RE: Liquid: How to handle null in result of fetchXML

    Request.params.id is not null. For testing I am just changing value. For instance, if right value is id=1, I have tried id=12 for testing and I am getting that error. Not sure if liquid can handle null.

  • Mahendar Pal Profile Picture
    45,095 on at
    RE: Liquid: How to handle null in result of fetchXML

    Agree with Ravi, my_query.results.entities should handle results for null as well

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Liquid: How to handle null in result of fetchXML

    Hi,

    I don't think you are getting this error because of the fetchxml is null, I think it is happening because of the error in the query itself due to the null value="{{request.params.id}}" ..

    I would suggest to put a check condition for this and only execute fetch if there is a valid id.

    Hope this helps.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans