Dynamics 365 (ADX) portal Show the top record from an entity view based using query filters in Dynamics 365 portals (ADX portals)

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.

Employee Name: },  Salary: }

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.

 

Create a HTML table dynamically from Entity List in Dynamics 365 portals (ADX portals)

After my recent posts on ADX portal, I came across a question on how to dynamically load an entity list in a web-page. For people knowing on how to use Liquid, basically the user was trying to render an entity list using the below syntax.

%

 

Unfortunately the entire entity list will not render like this. Rather if the entitylist loads successfully, it would execute anything within the entity list block.

So if I write something like below.

 

Entity list Loaded successfully

 

It would render “Entity List Loaded Successfully”

So is there no way. Off-course, where there is will, there is a way.

So I decided to try the below approach. Please note that code does not give the entire solution as you would need lot of styling to achieve the final goal but this can definitely get you started.

Step 1: Create a web-template

The first step is to create a web-template. Since I would creating the HTML table dynamically, I require a web-template.

Go to CRM –> Portals –> Web templates

Select New and then the new template screen would be presented. Below is the screenshot of my template.

image

I have named id “Custom Grid Template”. Don’t worry about the source. Here it is below for full reference.

}

 

 

}

}

}

The code covers most of the scenarios that you are going to need to render a HTML table from EntityView or EntityList. Let’s run through all the highlighted parts.

  • First an entitylist is loaded with the statement :
  • Second I take the default entityview of the entitylist. You can load the view with a specific name as well.
  • In third highlighted section, I write code to create the header.

}

  • Pretty simple isn’t it. In the next highlighted rows, I first traverse through the existing rows of the view and find the attribute for each column using
  • The interesting part is checking for the attribute type

}

Till this point, I was OK. However to be honest, I was completely stuck on how to identify EntityReference and picklist.

And finally this came my to rescue. https://docs.microsoft.com/en-us/dynamics365/customer-engagement/portals/render-entity-list-current-page

A bit nerdy but awesome it is.

Step 2: Load the web template dynamically in the webpage

Below is the code for the same.

 

And once you are done, below is the HTML table rendered dynamically. Off-course it is raw, but with a bit of styling it can look great.

image

 

Please visit orignal page

Show the top record from an entity view based using query filters in Dynamics 365 portals (ADX portals)

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *