Hello Everyone,
This is my first ever post with D365 Portals. I will bring up more interesting ones as we go along. Today I am going to talk about how you can customize your portal’s web template to use CRM fetch query with liquid.
Prerequisites:
- FetchXML using Advanced Find in CRM
- Customizing D365 Portals
Scenario:
D365 CRM provides an ability to categorize your articles using ISH (Interactive Service Hub). Those categories are used as tags and then displayed on D365 Portals as a list to browse the articles from. I will showcase how to modify the existing template and using FetchXML instead.
Build your FetchXML using Advanced Find
- Go to Advanced Find
- Select the entity as “Categories”
- See FetchXML Sample
<fetch mapping=”logical” returntotalrecordcount=”true” count=”{{ count }}”>
<entity name=”category”>
<attribute name=”categorynumber” />
<attribute name=”title” />
<attribute name=”createdon” />
<attribute name=”categoryid” />
<order descending=”false” attribute=”title” />
</entity>
</fetch>
Review existing web template:
- Go to D365 Online Instance – CRM
- Go to Portals > Web Templates > Knowledge Base Home
- Open the record
- You will see the below code:
{% extends ‘layout_1_column’ %}
{% block main %}
{% include ‘Page Copy’ %}
{% assign category_url = sitemarkers[‘Category’].url %}
{% assign count = count | default: 0 %}
{% assign categories = knowledge.categories | top_level: count %}
{% if categories %}
{% endif %}
Modify the Web Template:
- Add the liqiuid objects in following format:
<!– New Category Display –>
{% extends ‘layout_1_column’ %}
<!– OLD Category Display –>
{% block main %}
{% include ‘Page Copy’ %}
{% assign category_url = sitemarkers[‘Category’].url %}
{% assign count = count | default: 0 %}
{% assign categories = knowledge.categories | top_level: count %}
{% if categories %}
{{ category.title }}
–>
{% endfor %}
{% endif %}
<!– OLD Category Display –>
<!– New Category Display –>
{% endfetchxml %}
{% assign categories = categories_query.results.entities %}
{% if categories %}
Articles by Categories
{% for category in categories %}
{{ category.title | escape }}
{% endfor %}
{% endif %}
<!– End New Category Display –>
</div>
{% endblock %}
You will see the categories are now sorted in order.
Hope you had fun customizing your Portals 🙂
-Apurv