web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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.

  • Mahendar Pal Profile Picture
    45,095 on at

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

  • Usmani Profile Picture
    25 on at

    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.

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans