Dev Dex

developer goals

Category Archives: Microsoft Dynamics 365 Powerapps Portals

Add more than one Entity Forms on Web Page in Dynamics 365/Powerapps Portal

Problem: one of my clients had requirements to redirect portal user to different entity form if they are primary contact. Thought hmm it is quite straight forward task and i quickly created a web template and added 2 entity forms with name using web template liquid tag on the same web template. Bingo! got the nice Red error “An entry with the same key already exists“.

Honestly, had come across this error before and after spending some more time to find whats going on. I realised, there is only one tag which was twice on the web template “Entity Form“, to make sure this tag is casuing a problem, i created another web templates and added entity forms one by one and was able replicate the issue!

Research: when i had this issue, i was under the impression that i should easily be able to find solution from community or blogs. However, i learnt “It is not possible to add more than one Entity Form on the Web page”. It actually made me ponder, there must be solution. So, i decided to test different approaches to see if any of them work because as a developer never say “No” they make it happen one way or another lol.

Solution: This solution will help to add two or more entity forms on the dynamics 365 portal or Powerapps portal web pages

I created main web template (quite basic)

1. Contact Web Template (Code)

{% extends 'Layout 1 Column' %}
{% block main %}
{% include 'Page Copy' %}

{% include 'Contact Entity Forms Web Template' %}

{% endblock %}

in the Contact Web Template I included another Web Template, to check if the logged portal user is primary contact.

2. Contact Entity Forms Web Template (Code)

{% if {{user.isPrimaryContact}} -%}
    {% include 'Primary Contact Route Template' %}
{% else -%}
    {% include 'Secondary Contact Route Template' %}
{% endif -%}

If user is a primary contact then i have included primary route Contact template

3. Primary Contact Route Template (Code)

{% entityform name: 'Primary Contact Route Entity Form' %}

and if portal user is secondary contact then inlcude other web template

4. Secondary Contact Route Template (Code)

{% entityform name: 'Secondary Contact Route Entity Form' %}

Basically one main web template is calling another web template as funtion, which has a condition based on that other web templates which contacts entity form are included in the 2nd web template, this simple solution worked Perfectly for me.

I’m not claiming this is best solution, there could be room to improvement. I hope it helps.