Dynamically Render Different Portal Entity form depending on field Value

In portals, we can have a requirement where the customer wants to display a distinct form of an entity to users based on the value on a field. This requirement can be achieved by using a custom web template where the form entity would be rendered based on conditions.

In this post, I have created an entity called Trip, created two different forms to be displayed to the portal end-users. The Birmingham form will be rendered if we set the depot option-set field to Birmingham and vice versa for the London Form.

Prerequisites for this post:

  • You should know basic dynamics portal customisations like creating entity forms and entity lists
  • You should be able to create web template and web pages.
The two highlighted form above will be rendered in portals
in the above Depot field, we have option set values of either London or Birmingham.

Portals should render two different forms depending on the value of the depot field. In the Image below, I have created a web template that takes a query string Id, using the Id to retrieve the depot field from dynamics, then checking the value of the option set. Depending on the value, it renders a distinct entity form

{%if request.params["id"] %}
{%fetchxml trips_query%}
    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
    <entity name="new_trip">
        <attribute name="new_tripid" />
        <attribute name="new_tripname" />
        <attribute name="createdon" />
        <attribute name="cr82e_depot" />
        <order attribute="new_tripname" descending="false" />
        <filter type="and">
        <condition attribute="new_tripid" operator="eq" uiname="Druck 3" uitype="new_trip" value="{{request.params["id"]}}" />
        </filter>
    </entity>
    </fetch>
{% endfetchxml %}

{% for trip in trips_query.results.entities%}
    <div class="content col-10">
    <div class="col-md-8">
        {%if trip.cr82e_depot.value == 968570000%}
        {%entityform name: 'ANS Trip from Birmingham'%}
        {%elsif trip.cr82e_depot.value == 968570001%}
        {%entityform name: 'ANS Trip from London'%}
    </div>
    </div>
{%endif%}
{%endfor%}
{% endif %}

Attach the web template to the web page that should render entity form. When you run the page, it should dynamically render one of two forms depending on the value of depot field.