toggle entity forms 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
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


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