D365 Portals - Using FetchXML with Liqiuid

2017-4-29 | apurvghai | Dynamics CRM SDK | C#


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 %}
      <div class="list-group unstyled">
      {% for category in categories %}
      <a href="'id', category.categorynumber }}" class="list-group-item">
      {{ category.title }}
      </a>
      {% endfor %}
      </div>
      {% endif %}
    

Modify the Web Template:

  • Add the liqiuid objects in following format
	<!-- OLD Category Display -->;
	{% 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 %}
	<div class="list-group unstyled">
	{% for category in categories %}
	<!-- <a href="'id', category.categorynumber }}" class="list-group-item">-->
	{{ category.title }}
	</a> -->;
	{% endfor %}
	</div>

	{% endif %}
	<strong><!-- OLD Category Display -->;</strong>

	<!-- New Category Display -->;
	<div class="list-group">
	{% fetchxml categories_query %}

	{% endfetchxml %}
	{% assign categories = categories_query.results.entities %}
	{% if categories %}
	<div class="list-group">
	<h4 class="list-group-item-heading">Articles by Categories</h4> <br /> <br />
	{% for category in categories %}
	<a class="list-group-item" href="'id', category.categorynumber }}{{ category.categorynumber | escape }}">{{ category.title | escape }}</a>
	{% endfor %}
	</div>
	{% endif %}
	<strong><!-- End New Category Display -->;</strong>
	</div>;
	{% endblock %}

You will see the categories are now sorted in order.

categories

Hope you had fun customizing your Portals :)
-Apurv


Recent Posts
Getting started with Dynamics 365 CRM SDK in C#
Jan 14, 19 | Dynamics CRM SDK
Using Postman with Dynamics 365 Online and OnPremise
Jan 14, 19 | Dynamics CRM SDK
Getting Started with WebAPI
Dec 28, 18 | Dynamics CRM SDK