Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Blogs / PowerApps 4 Devs / PowerApps Portals: WebTempl...

PowerApps Portals: WebTemplates, Hard as Liquid!!!

On this post, we will look into extending Dynamics 365 Portals templates using a template language called Liquid. https://help.shopify.com/en/themes/liquid

If you have used Dynamics 365 Portals SaaS version, you have seen the limitations when it comes to CRUD operations. Below is a sample on how Liquid can help us read Dynamics 365 CE data.

Suppose you need to read a record with three fields. Theyr are called "dantas_eventname", "dantas_eventstartdate" and "dantas_eventenddate" from a particular entity called "dantas_event".

After reading the data, you would package the result in json format, so that a target page or control can consume it. (I usually use this strategy if the required datasource is reused by other portal pages, and/or javascript based UI components). Here is a sample:

{% assign eventid= request.params['id'] %}

{% fetchxml event_data %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" count="1" top="1">
    <entity name="dantas_event">
        <attribute name="dantas_eventname" />
        <attribute name="dantas_eventstartdate" />
        <attribute name="dantas_eventenddate" />
        <attribute name="dantas_eventid" />
        <order attribute="dantas_eventname" descending="true" />
        <filter type="and">
            <condition attribute="dantas_eventid" operator="eq" value="{{ eventid }}" />
        </filter>
    </entity>
</fetch>
{% endfetchxml %}



{% for item in event_data.results.entities %}
{
    "eventid": "{{ item.dantas_eventid }}",
    "eventname": "{{ item.dantas_eventname }}",
    "startdate": "{{ item.dantas_eventstartdate}}",
    "enddate": "{{ item.dantas_eventenddate}}"
}
{% endfor %}

*After adding your code be sure to set the Webtemplate's Mime/Type field to "application/json".

If you are dealing with a single record result query, you may want to use one of the pre-built objects to fetch the data in a much simpler way. In this case, you can use the entities Dynamics 365 Portal Liquid object.

Here is what it would look like:

% assign event_data = entities['dantas_event'][request.params.id] %}

{% if event_data %}
{
    "eventid": "{{ event_data.dantas_eventid }}",
    "eventname": "{{ event_data.dantas_eventname }}",
    "startdate": "{{ event_data.dantas_eventstartdate}}",
    "enddate": "{{ event_data.dantas_eventenddate}}"
}
{% endif %}

There many other pre-packaged Dynamics 365 Liquid objects. Below is a list of the ones I've used the most:

  • page 
  • entities : Allows access to any D365 CE entity by ID
  • now: Renders current UTC time
  • params : Shortcut to request.params
  • settings : Allows access to Portal site settings
  • snippets: Allos access to Portal snippets
  • user : Refers to the portal user and its D365 attributes
  • Other dynamic tags : chart, powerbi* (requires portal configuration), editable, entityform, entitylist, entityview, 

You can find more information about them here : https://docs.microsoft.com/en-us/dynamics365/customer-engagement/portals/liquid-objects

Comments

*This post is locked for comments