Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Portal - Rendering the wrong template

(0) ShareShare
ReportReport
Posted on by 412

Hello everyone, 

Only recently I started to work with Portals and I would really appreciate your help!

Here my Issue:

I have created 2 Web Pages that have the same parent web link:

- customer/active-customer;

- customer/prospect-customer;

Both are using different custom templates where I am deciding which is the right entity list to display, actually the templates have almost the same content and the only difference is the key value of entity list that they should call.

Somehow, both of my pages are using only one of the templates, I have checked the pages properties and I am sure that the template names used are correct.

Template1

   {% fetchxml webroleList %}
  <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
  <entity name="adx_webrole">
    <attribute name="adx_webroleid" />
    <attribute name="adx_name" />
    <order attribute="adx_name" descending="false" />
     <link-entity name="adx_webrole_contact" from="adx_webroleid" to="adx_webroleid" visible="false" intersect="true">
      <link-entity name="contact" from="contactid" to="contactid" alias="ab">
        <filter type="and">
          <condition attribute="contactid" operator="eq" value="{{user.id}}" />
        </filter>
      </link-entity>
    </link-entity>
  </entity>
</fetch>
  {% endfetchxml %}
   {% for item in webroleList.results.entities %}      
        {% if item.adx_name == 'Role1' %}  
        {% include "entity_list" key:"Partial-ActiveCustomer-List" %}
        {% endif %}
        {% if item.adx_name == 'Role2' or item.adx_name == 'Role3' or item.adx_name == 'Role3' %}  
        {% include "entity_list" key:"Full-ActiveCustomer-List" %}
        {% endif %}   
    {% endfor -%}

Template2

   {% fetchxml webroleList %}
  <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
  <entity name="adx_webrole">
    <attribute name="adx_webroleid" />
    <attribute name="adx_name" />
    <order attribute="adx_name" descending="false" />
     <link-entity name="adx_webrole_contact" from="adx_webroleid" to="adx_webroleid" visible="false" intersect="true">
      <link-entity name="contact" from="contactid" to="contactid" alias="ab">
        <filter type="and">
          <condition attribute="contactid" operator="eq" value="{{user.id}}" />
        </filter>
      </link-entity>
    </link-entity>
  </entity>
</fetch>
  {% endfetchxml %}
   {% for item in webroleList.results.entities %}      
        {% if item.adx_name == 'Role1' %}  
        {% include "entity_list" key:"Partial-ProscpectCustomer-List" %}
        {% endif %}
        {% if item.adx_name == 'Role2' or item.adx_name == 'Role3' or item.adx_name == 'Role3' %}  
        {% include "entity_list" key:"Full-ProscpectCustomer-List" %}
        {% endif %}   
    {% endfor -%}

 

Note:

Something maybe worth to mention is the fact that all the entity lists belong to the same CRM entity.

The template was working when I had only one, but customer wanted to divide further the list  and the result in different pages and I had to switch from 2 to 4 entity list & from 1 to 2 web pages.

Many thanks in advance!

*This post is locked for comments

  • Verified answer
    Irena Benja Profile Picture
    Irena Benja 412 on at
    RE: Portal - Rendering the wrong template

    Hello,

    I was sure that my template was correct, just wanted to share in order to make more clear what I was intending to do.

    Was able to find the problem, was actually very stupid mistake:

    When I created the second Web Page I used the existing Template Page, just to show something to the users while I was developing. After creating the new Page Template [with the correct Liquid Template] I did the change to the Web Page, however there was still exiting a record under Page Template associating it to this Web Page.

    Those records are auto generated and it didn't came to my mind checking there earlier.

  • Suggested answer
    Arpit Shrivastava Profile Picture
    Arpit Shrivastava 7,518 User Group Leader on at
    RE: Portal - Rendering the wrong template

    Hi Ira,

    Your custom template code looks fine. I am not seeing any issue with the code but there might be some issue in webpage configuration though.

    Please, double check you have associated your Custom Page Template (which is associated with your custom Web Template) with Localized Content and Root Web page both.

    It would be more helpful to find the root cause If you could provide more details about your webpage configuration (any screenshot).

    Also, I would also like to suggest you, rather using Fetch XML to get the Portal Logged In User Roles, you could have used following syntax:

    {% if user.roles contains 'role1' %}
    User has role1.
    {% endif %}

    https://community.adxstudio.com/products/adxstudio-portals/documentation/configuration-guide/liquid-templates/objects/user/



    If found useful, please mark the answer as verified.


    Cheers
    Arpit
    https://arpitmscrmhunt.blogspot.com

     

  • Irena Benja Profile Picture
    Irena Benja 412 on at
    RE: Portal - Rendering the wrong template

    Hello Arpit,

    Thanks for your answer!

    I am familiar with this approach that you are suggesting but I wanted to achieve it using the templates.  The project I am working has 6 web roles and only for the entity that I am currently working  I have to create 4 different lists. There are many possible combination role - pages and I see this escalating.

    My idea was instead of creating many pages for the same entity better create one and call there the right entity list.

    I am sure that your suggestion will work, still I wanted to know whats wrong with the template behavior and if anyone had similar issue.

    Regards,

    Irena.

  • Suggested answer
    Arpit Shrivastava Profile Picture
    Arpit Shrivastava 7,518 User Group Leader on at
    RE: Portal - Rendering the wrong template

    Hey Ira,

    After analyzing your code what I understood is, you are trying to show different-2 Entity Lists to the portal users based on their web roles.

    As per my experience, I don't think it would require code to achieve this, you could have rather achieve it through Portal OOB configurations.

    The solution is - Web page Access Control Rule

    (https://docs.microsoft.com/en-us/dynamics365/customer-engagement/portals/webpage-access-control)

    Suppose my requirement is, if the portal user is having role1 then show Partial-ActiveCustomer-List, else if the user is having either role2 or role3, then show Full-ActiveCustomer-List. To achieve this,

    I will create two same names of web links (customer/active-customer). One web link will associate with the webpage(webpage1) which is associated with Partial-ActiveCustomer-List and One web link will associate with the webpage(webpage2) which is associated with Full-ActiveCustomer-List.

    Now we have to hide and show these web links based on portal user roles and role1 users should see webpage1 and role2,role3 users should see webpage2. To achieve this,

    We will create a new webpage access control rule for webpage1 and Grant its access to role1 users only same will create a new webpage access control rule for webpage2 and Grant its access to role2 and role3 users only.

    By doing this, if the user having role1 will login on the portal, he/she will able to see the weblink only which is associated with webpage1, not other. Same, role2 and role2 will be able to see their associated webpage weblink. So the idea is, role1 user won't able to see weblink of role2,role3 and vice-versa.

    Here how webpage access control rules configure. This feature is especially to achieve this type of requirement only:

    For role1:

    61764.Capture1.PNG

    For role2 and role3:

    61764.Capture1.PNG

    Change webpage name in both the access control rules.

    Hope you understood.

    If my answer helped to resolve your issue, kindly verify it by clicking 'Yes'. It would be helpful to the other community members seeking to resolve a similar issue.


    Cheers
    Arpit
    https://arpitmscrmhunt.blogspot.in

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans