'How to dynamically change fetchxml filters in Dynamics Portal using Liquid templates?
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 %}
Solution 1:[1]
Fix this snippet, you have double curly for if:
{{% if {{ RecordId }} %}}
Correct code:
{% if {{ RecordId }} %}
Solution 2:[2]
{% 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 %}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Arun Vinoth - MVP |
| Solution 2 | Dandydon |
