{Know How} 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.

{% entitylist name:”Account List” }%

{% endentitylist %}

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.

{% entitylist name:”Account List” %}

Entity list Loaded successfully

{% endentitylist %}

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.
{% entitylist name:”Account List” %}
{% entityview %}
{% for col in entityview.columns %}
{{col.name}}

{% endfor %}

{% for e in entityview.records %}

{% for c in entityview.columns %}
{% assign attr = e[c.logical_name] %}
{% assign attr_type = attr.attribute_type|downcase %}
{% if attr.is_entity_reference %}
{{attr.name}}
{% elseif attr_type == ‘picklist’ %}
{{ attr.label }}
{% else %}
{{ attr }}
{% endif %}

{% endfor %}

{% endfor %}
{% endentityview %}
{% endentitylist %}
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 : {% entitylist name:”Account List” %}
  • Second I take the default entityview of the entitylist. You can load the view with a specific name as well. {% entityview %}
  • In third highlighted section, I write code to create the header.

{% for col in entityview.columns %}
{{col.name}}

{% endfor %}

 

  • 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

{% assign attr = e[c.logical_name] %}

  • The interesting part is checking for the attribute type 

{% if attr.is_entity_reference %}
{{attr.name}}
{% elseif attr_type == ‘picklist’ %}

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.

{% include ‘Custom Grid Template’ %}

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

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For training/ consulting please email at info@xrmforyou.com

Visit our products page – http://www.xrmforyou.com/products.html

 

{Quick Tip}–Dynamically show/ hide entity forms in Dynamics 365 portals (ADX portals) depending on Business Logic using Liquid templates

As I have been working mostly on Dynamics 365 portals, here goes another D365 portal post.

So here is the requirement. The portal customer applies for loan and then views the status of the loan request through the portal. However for every customer, there is one contact who is kind of Power User and is hence able to view some additional details on the Loan Request Form which the regular portal customers are not able to see,

The additional details are like.

  • The internal user with whom the loan request is currently pending
  • Additional internal communications among the internal team regarding the loan request.

So here is the set-up.

  • Two Forms for loan request entity
    • General form visible to all the users
    • Admin form visible to only the power users which shows the additional details

In the portal there is loan request web-page, which depending on the logged in-user, renders the Admin form.

To determine whether the portal user is a Power User or not, there is a field on the contact entity – “Is Power User” which need to be set. Below is the screenshot for the same.

schema name for the field – new_ispoweruser

image

Creating a loan request entity and then showing it up for the demo would take lot of time and also can’t use the screens from the client system due to legal issues. So here I would basically show you with the account entity, how you can dynamically render a entity form based on condition using Liquid.

Step 1 : Create a Blank Web-Page and set it up in the Portal Navigation

Go to CRM –> Portals –> Web Pages –> New

image

As you can see, I have created a Web Page with template as Blank Page. Notice carefully that I have not set any entity form or entity list. This is because I am going to set those up dynamically depending on conditions.

Now login to the portals as admin contact and then include this web page in the Navigation.

image

image

Clicking on Loan Status gives an empty page because we are using the blank page template.

2. Setting up of Entity forms

Now to mock up the previous scenario, I have created two forms for account entity.

  • Loan Request Admin Form
  • Loan Request General

image

Create Two entity Forms in CRM based on these two forms.

image

image

3. Set up the forms Dynamically using Liquid.

Login to the portal using the admin contact and edit the Copy content of the Loan Status Page.

image

Enter the below Liquid Code in the editor.

image

Pasting the same code inline

{% if user %}

{% if user.new_ispoweruser == true %}

{% entityform name:"Loan Request Admin Form" %}

{% endif %}

{% endif %}

{% entityform name: "Loan request General Form" %}

The code is pretty simple. All it is doing is checking if the logged in portal contact is a power contact, then load the admin form. The general form is always loaded by default

Save it and now when you refresh the page, you would see the power user is able to see both the forms. Using the same construct, you render forms dynamically based on business conditions.

Hope this helps.

Debajit Dutta

(Dynamics MVP)

For training/ consulting please email at info@xrmforyou.com

Visit our products page – http://www.xrmforyou.com/products.html

{In-depth walkthrough}–Redeeming invitations, modifying invitation email and disabling open registrations in Dynamics 365 portals (ADX portals)

It’s been sometime that I have written a blog. Has been a lot for the past 2 months, personally and professionally and finally I am delighted to pen this down.

Has been working on Dynamics 365 portals lately a lot and thought of sharing some of my experience in user registration and redeeming invitations.

Here is my Dynamics Customer who has set-up D365 portals and want that users should not able to register by themselves.  Just for a bit of explanation, when you first time set-up D365 portals, the portals would allow a someone to register using custom identities through the Register Tab. Check for the below screenshot.

 

image

As you can see, all a user needs to do is enter an email address, set-up a user name and password and then register. Internally that would create a contact in CRM. Please note that the portal contact at this point of time would not have any roles associated to it and hence they won’t be able to see any authenticated content. However, there is a potential problem that your CRM contacts would be flooded with unwanted registrations.

So we needed to disable that. But how?

The feature is actually called ‘Open Registration’ in D365 portals.

Disable Open Registration in D365 portals

Go to Portals –> Site Settings in CRM

Search for Setting –> Authentication/Registration/OpenRegistrationEnabled and open the record.

Set the value of the setting to false and Save it back.

image

Now if you clear your cache and open your website in the portals, you would find the option to Register is missing.

image

 

Great! We have disabled user self registrations. Now what our customer wanted was to register portal users only through the invitation code. So basically the process is, the CRM administration would send invitation to the contact from the Contact. The contact would receive the invitation email in his/her email and then click on the email to register themselves with the portal.

So let’s see how it should be done. From the above point it is apparent that the email being sent out to the contact is one of the major component in this redeeming process. So let’s go ahead and first check what’s in the email.

Configuring the email to send Invitation:

Go to CRM-> Settings-> Processes

Search for the process – “Send Invitation”

Open the workflow and de-activate it. It should look like below.

 

 image

Click on the ‘Set Properties’ in the highlighted step in the above email.

Once the email editor opens, just check for the email body. Below is the highlighted email body.

image

You can actually modify the email as per you needs. However the most important area of the email is setting the value of the URL highlighted above. This should be the same url the user is redirected when he/ she clicks on the ‘Redeem Invitation’ tab.

image

The url would be in the format – https://<your portal name>/register.

Just copy this URL and paste it in the email body.

image

Save & Close and activate the workflow.

 

Now we are at the final step

Sending Invitation to the contact:

Go to the contacts section in CRM and select the contact for which you want to send the invitation and then Click on the ‘Create Invitation’ on the ribbon menu.

image

 

You can set the expiry date of the invitation, the associated account for the portal contact on successful redeem.

image

 

Save it. Once saved, an invitation code would be automatically generated.

image

there is one more thing that you can do once a contact successfully register themselves using the invitation code.

You can set the We-roles for the user. I selected ‘Authenticated User’ web-role

image

 

Great! So now the invitation should be sent.

Click on Run Workflow from the ribbon and then select the ‘Send Invitation’ workflow we modified.

image

Once run, the user would get an email with the registration link. Below is the sample user registration link that the portal contact would receive in email.

https://xrmportal2.microsoftcrmportals.com/Register/?returnurl=%2f&invitation=EP2f2DlBSXdyww0ZUlcf92NC15YZJFeU-f3B6GNRWTLVOGA1rZ4h1SGxh8PJJOGiA5H7l1GFwXhcbnBCJCI3DNd-96cmQ3NQagxJLcFsd5XvNVCN3K3e5O38n9kS6vW5nVXJyg6wfwhEjCvebslf9II3vJq57gvNBuH2G0QTE-I-

 

Clicking on the above link, the portal user would redirected to the redeem page.

As you can see from the below screenshot, the invitation code is automatically inserted in the box.

image

 

Clicking on register will take to the next screen where the portal user can choose a login username and password of their choice. However

image

All set and done and the portal contact is now able to login to the D365 portal.

If we go back to CRM now, you would see the contact is now having an associated Web Role – ‘Authenticated Users’

image

 

P.S – > If you do not see the Redeem Invitation tab in your portal, there is some issue in Site settings. Please make sure the below site setting is enabled as true.

image

For developers/ customizers graduating from ADX 7.0 to D365 portals, in ADX 7.0  the Redeem Invitation tab was enabled using the site setting –> Authentication/Registration/RequiresInvitation

However this setting didn’t work for me in Dynamics Portals and it seems to have been replaced with the Site Setting –> Authentication/Registration/InvitationEnabled

Hope this helps!

 

Debajit Dutta

(Dynamics MVP)

For training/ consulting please email at info@xrmforyou.com

Visit our products page – http://www.xrmforyou.com/products.html