How to dynamically change fetchxml filters in Dynamics Portal using Liquid templates?

1.5k views Asked by At

Based on querystring I need to change FetchXML filters for dynamics portals using liquid. I tried below but it throws exceptin; Unknown tag 'endif'. Please help to make the filters dynamic.

{% fetchxml fetchActivities %}
    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
        <entity name="xyz_testentity">
          <attribute name="xyz_testentityid" />
          <attribute name="xyz_name" />
          <order attribute="xyz_name" descending="false" />
          <filter type="and">
            {{% if {{ RecordId }} %}}
            <condition attribute="xyz_tempattr" operator="eq" value="{{RecordId}}" />
            {% else %}
            <condition attribute="xyz_tempattr" operator="not-null" />
            {% endif %}
          </filter>
        </entity>
      </fetch>
    {% endfetchxml %}
2

There are 2 answers

0
Arun Vinoth-Precog Tech - MVP On

Fix this snippet, you have double curly for if:

{{% if {{ RecordId }} %}}

Correct code:

{% if {{ RecordId }} %}
1
Dandydon On
{% assign RecordId = request.params['RecordId'] %}
{% fetchxml fetchActivities %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
    <entity name="xyz_testentity">
      <attribute name="xyz_testentityid" />
      <attribute name="xyz_name" />
      <order attribute="xyz_name" descending="false" />
      <filter type="and">
        {% if RecordId %}
        <condition attribute="xyz_tempattr" operator="eq" value="{{RecordId}}" />
        {% else %}
        <condition attribute="xyz_tempattr" operator="not-null" />
        {% endif %}
      </filter>
    </entity>
  </fetch>
{% endfetchxml %}