cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

Query entity details with lookup field using Liquid

I have an entity with a lookup from another entity. I added this lookup using the relationship tab in the entity details. I have a department entity and programmer entity. The programmer entity has a field lookup to the department entity. I would like to get a list of programmers based on the department ID query string passed. 

 

My code looks like this: 

 

{% fetchxml programmers %}
      <fetch version="1.0" mapping="logical" output-format="xml-platform" distinct="true" returntotalrecordcount="true">
        <entity name="syst_programmer">
          <attribute name="syst_name" />
          <attribute name="syst_department" />
          <link-entity name="syst_department" from="syst_department" to="syst_departmentid" visible="true" link-type="outer" alias="ai">
            <attribute name="syst_departmentid" />
            <attribute name="syst_name" />
          </link-entity>
        </entity>
      </fetch>
      {% endfetchxml %}

{% if programers.results.total_record_count > 0 %}
{% assign id = request.params['id'] %}
      <div class="row">
        {% for p in programmers.results.entities %}
        <div class="col-md-4" style="text-align: center;">
          <a href="/departments/departmentinfo?id={{id}}">
            <H4>{{p.syst_department.syst_name}}</H4>
            {{p['ai.name']}} (this is alias value)
    
            </br>
          </a>
        </div>

        <!-- Note filtering of currency format -->
        {% endfor %}
      </div>
      {% endif %}

I am not sure how to use the link-entity, what's the correct format for it here? Any examples out there for the power apps portals? I'd like from the ID of the department, to display the name of the department, and then a list of all programmers that have that department as a lookup. 

Thanks for any guidance. 
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Hi

can you change this line:

      {% if programmers.results.total_record_count > 0 %}

 to this:

      {% if programmers.results.entities.size > 0 %}

also I noticed that now you are no longer using join/link-entity, which is fine 

but notice that as you made the search in Advanced Find it is now hard-coded the GUID of your department

that's not a problem as long as you have the same GUID in all environment

another option would be filtering (in advanced find) by the Related Entities, and then searching by name.. this would generate the join in your fetch




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

View solution in original post

8 REPLIES 8
Highlighted
Super User II
Super User II

Hi

 

What's the issue you are facing? are you getting any errors or not returning results..

did you create entity permissions for both entities?

 

just one thing in your code might be wrong:
p['ai.name']}}
you might be missing the attribute prefix
p['ai.syst_name']}}

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

 




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

Highlighted

Hi @OliverRodrigues  Thanks for your response! 

 

Yes I have set entity permissions on both the department and programmer entities. I also changed the attribute reference to be ai.syst_name .

It's giving me this error: 

 

Liquid error: Exception has been thrown by the target of an invocation.

 

When I remove the linked entity code from fetch xml, the error is gone, that's why am not sure if this is the right syntax? 

This is the code that's when removed hides the error: 

 

    <link-entity name="syst_department" from="syst_department" to="syst_departmentid" visible="true" link-type="outer" alias="ai">
            <attribute name="syst_departmentid" />
            <attribute name="syst_name" />
          </link-entity>


I saw some posts on the internet without the "to" attribute, or makes it point to something like parented. But I don't understand how these work? I started with it simple without even filtering based on the current ID, but it's not working.. my end goal would be to have the link entity filtered by the current passed ID in the query string. 

 
 
Highlighted

you should keep both from and to as a good practice

from your code:

from="syst_department" 

to="syst_departmentid"

 

the from is usually the primary key from the linked entity.. so it should be syst_departmentid

the to should be the logical name for the lookup in your child entity, can you double check what is the name for that?

 

what you can always do is generate the fetchxml via Advanced Find, saves you a lot of time 




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

Highlighted

@OliverRodrigues 
Thank you for the advanced find, I didn't know about that. 

I generated the fetchxml code, it returns a result in the advanced find, but when added to my liquid code, it's not returning anything (no error, but 0 result), here's my code: 

 
 
 {% fetchxml programmers %}
      <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
        <entity name="syst_programmer">
          <attribute name="syst_programmerid" />
          <attribute name="syst_name" />
          <attribute name="createdon" />
          <attribute name="syst_department" />
          <attribute name="syst_about" />
          <order attribute="syst_name" descending="false" />
          <filter type="and">
            <condition attribute="syst_department" operator="eq" uiname="JavaScript" uitype="syst_department" value="{69CF501D-98C3-EA11-A812-000D3ABA3FFB}" />
          </filter>
        </entity>
      </fetch>
      {% endfetchxml %}
 
      <!-- Parse through results -->
      {% if programmers.results.total_record_count > 0 %}
     test
      <div class="row">
        {% for p in programmers.results.entities %}
      test in loop
        <H4>{{p.syst_name}}</H4>
        <div class="col-md-4" style="text-align: center;">
            <H4>{{p.syst_department}}</H4>
            </br>
        </div>
        <!-- Note filtering of currency format -->
        {% endfor %}
      </div>
      {% else %}
      no result
      {% endif %}


I always see the "no result"

Any idea?
The fetchxml code is what I downloaded from the advanced find.
Highlighted

Hi

can you change this line:

      {% if programmers.results.total_record_count > 0 %}

 to this:

      {% if programmers.results.entities.size > 0 %}

also I noticed that now you are no longer using join/link-entity, which is fine 

but notice that as you made the search in Advanced Find it is now hard-coded the GUID of your department

that's not a problem as long as you have the same GUID in all environment

another option would be filtering (in advanced find) by the Related Entities, and then searching by name.. this would generate the join in your fetch




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

View solution in original post

Highlighted

That worked! Thanks!

 

But what's the difference between doing the filter with how I did it now, and doing it based on a related entity? 

Highlighted

Brilliant.. can you mark as the solution so it can help other people as well?

 

if you are working on DEV environment, once you go to TEST / PROD you need to make sure the GUID of the records are the same.. if not your fetch won't work as it won't find a record with that GUID




If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Power Apps Portals Super User


Oliver Rodrigues


 

Highlighted

Thanks for the help! 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Users online (15,930)