Show the top record from an entity list in Dynamics 365 portals/ powerapps portals using liquid

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com
This is one more of my recent articles on ADX portals and this blog I am going to write on how to select the topmost record from an entity view using query filters.
Can’t depict the exact business scenario here but probably an example will get you started on how to get started with the query filters.
So let’s take an example here – What if someone asks you to print the the details of an employee with the highest salary from a specific view?
Let’s assume there we are leveraging the Contact table in CRM for Employee.
And the view I select is “Active Contacts” view.
Schema name of the salary field in the contact table – “new_salary”
In CRM, I created an Entity List called “Contact List” with a view “Active Contacts”
image
In the Portal side, in the Copy field just paste the below code.

{% entitylist name:"Contact List" %}
{%entityview logical_name:"contact", name:"Active Contacts" %}
{% assign records = entityview.records| order_by: 'new_salary', 'desc'%}
{% assign records2 = records| take: 1 %}
{% for record in records2 %}
Employee Name: {{ record.fullname }},  Salary: {{ record["new_salary"]}}
{% endfor %}
{% endentityview %}
{% endentitylist %}

The code is pretty simple. I load the entity view “Active Contacts” from the Entity List “Contact List” that I created in the previous step.
The important part is the code highlighted in yellow.
I just take the output of view and then order by salary descending (default order is ascending) and in the next line I just take the top record from there.
That’s all. I now just print out the Employee Name and the Salary of the employee. Not a real world example but probably helps you get the idea.
-Debajit Dutta
(Dynamics MVP)
For training/ consulting please email at info@xrmforyou.com
Visit our products page – http://www.xrmforyou.com/products.html


Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading