web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Portal - Using Liquid variables within Entity List custom javascript

(0) ShareShare
ReportReport
Posted on by 55

Hi all,

My scenario is that I have an entity list and within its custom JavaScript I can filter rows out based on attributes in the view. So a basic example is like this. Note I'm using liquid to get the logged in users id. 

$(document).ready(function (){
var user = '{{user.id}}';
console.log("user: " + user);
$(".entitylist.entity-grid").on("loaded", function () {
$(this).children(".view-grid").find("tr").each(function (){
var qualaimcode = $(this).find('[data-attribute="aa.uow_qualificationaimcode"]').attr("data-value");
if (qualaimcode == "25") {
//$(this).css("background-color", "yellow");
$(this).remove();
}
});
});
});

Running this will show the users contact id in the dev console.

The web template displaying this entity list is currently using the OOB page template 'Web Form' which is of type 'rewrite' and therefore not customizable.


I want to use a web template rather than a rewrite template so i can use a fetchxml query to get related entity data for the logged in user

 but on doing this i find that {{user.id}} in my custom JavaScript is now treated as text.

Looking into this it seems that when using web templates any liquid code does not get evaluated.


So how do I get around this? I need to filter my entity list based on the 'qualaimcode' of the currently logged in user. I can get this info

via liquid template but don't seem to be able to use it to filter within my entity list custom JavaScript.


Thanks.

I have the same question (0)
  • oliver.rodrigues Profile Picture
    4,052 on at

    Hi actually you don't need all this work to filter the list

    in terms of the web template, you don't need to use the "Web Form", your can use the "Full Page" as a Page Template that will give you what you need

    now in your entity list, there is a section "Filter Conditions" where you can filter for an attribute from the logged in user, make sure also your entity list is enabled for entity permissions, this way you also filter automatically by the user

    5025.entitylist.PNG

  • terryharrison Profile Picture
    55 on at

    Hi Oliver,

    Thanks for that but the entity list filter conditions only allow me to filter based on user or account attributes, so basically contact lookups / created by / owner etc. what I need to filter by is a custom entity attribute that is not one of these.

    So For logged in user I have a contact id. from there I need to go via a 'course' custom entity to get a qualification code. e.g. 25. I can get this using fetchxml in liquid template.

    I then need to filter the entity list in custom JavaScript to only show rows (jobs) where the jobs qualification code is 25 also.

    Hope this makes more sense.

    Thanks

  • Nicholas Hayduk Profile Picture
    2,863 on at

    Hi,

    I've got some blog posts on the subject, if you're interested:

    www.engineeredcode.com/.../inconsistent-behavior-of-liquid-in-the-custom-javascript-attribute-on-entity-lists-in-dynamics-365-portals

    www.engineeredcode.com/.../dynamics-365-portal-how-does-the-entity-form-or-entity-list-get-on-the-page

    In your situation, I'd use the Custom JavaScript that is available on your Web Page record.  It should evaluate the Liquid.

    Hope that helps.

    Nick

  • Fubar Profile Picture
    2,761 on at

    Can you construct the query using Advanced Find for a specific User - if the answer is Yes then you may be able to implement this without a lot of custom work - there used to be a trick that when a View made use of a Contact in the query that the Portal would auto substitute in the currently logged in Portal user (you will also find a Portal Contact record [can't remember what its named] was installed in you list of contacts when the portal was setup).

    To go down the path in your original post...….

    • Create your own Web Template (you can copy the content of one of the existing ones like Layout 1 Column)
    • Inside your Web Template write a script tag from Liquid to define the JS variable (in your own Web Template you can run Fetch and loop results etc if needed - just be aware that the when doing Fetch the entity access permissions of the Portal User are applied)
    • Then refer to the variable from inside your JavaScript in the $(document).ready rather than defining it in the JavaScript (and put the JavaScript in the provided locations not embedded in the page Content)

    In the Web Template you can just add something like the following at the top of it.

    <script type="text/javascript">

       var myUser = '{{user.id}}';

    </script>

    I think you may end up having to rebuild your own entity list (there is an example in the Admin Guide), as you will have to worry about pagination etc (unless you know that your result set will always be a low record count)

  • Suggested answer
    terryharrison Profile Picture
    55 on at

    Thanks all for the suggestions. I got round this in the end by creating an OData feed for the related entity and then doing it all in the custom JavaScript. So I get the user details then pull filtered results from the OData feed using XMLHttpRequest to get that users course details. I can then store this in a variable and use it to filter the entity list.

  • bik@inturi Profile Picture
    75 on at

    Hi

    How did you manage to do it in the end.  I have similar issue, I have a entity list .. that gets populated form a View.  I then need to further filter it depending on a list of contact I have in another list.

    At the moment the entity displays all contacts.

    THanks

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans