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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Liquid code giving err...
Power Pages
Answered

Liquid code giving error while fetching Entities data using FetchXML

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi Experts,

 

I am trying to fetch the Entities data using fetchxml (application/json) but when I am executing the url then it is giving below error:

 

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

Below is the code:

 

{% assign fullname = request.params.['fullname'] %}

{% assign cachestring = request.params.['cachestring'] %}

{% fetchxml feed %}
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
 <entity name='contact'>
 <attribute name='fullname' />
 <attribute name='emailaddress1' />
 <attribute name='contactid' />
 <attribute name='firstname' />
 
 <order attribute='First Name' descending='true' />
 <filter type='and'>
 <condition attribute='fullname' operator='eq' value='{{fullname}}' />
	 
	 <condition attribute='fullname' operator='ne' value='{{cachestring}}' />
 
 </filter>
 
 </entity>
</fetch>
{% endfetchxml %}

 
 [
 {% for item in feed.results.entities %}
 {
 "Contact_id": "{{ item.contactid }}",
 "Contact_Name": "{{ item.fullname }}",
 "Contact_Email": "{{ item.emailaddress1 }}",
 "Contact_First_Name": "{{ item.firstname }}"
 
 }{% unless forloop.last %},{% endunless %}
 {% endfor %}
 ]

 

 trying to get the contact entities data.

I have followed below blog to create the Web Template --> Page Template --> Web Page.

 

One more query I have that In blog there is a params variable that is included in code. I understood why those parameters are included (i.e to filter the data) but how and from where we pass those parameters to get the filter data. Is that when we do an ajax call to read the data then we pass those parameters?

 

Also, How do we get the currently logged-in user unique id to filter the entities data and also the related entities data?

 

Please help me with this issue.

 

Thanks,

Amit

Categories:
I have the same question (0)
  • oliver.rodrigues Profile Picture
    9,482 Most Valuable Professional on at

    hi.. I see a simple error in the way you are getting the query string parameter

     

    {% assign fullname = request.params.['fullname'] %}

    there is no "." after params, try the below:

    {% assign fullname = request.params['fullname'] %}

    do the same for the "cachestring" and give it a go

     

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

    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.

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    HI @OliverRodrigues 

    I have made that change but still getting the same error.

    Please suggest if I am missing anything. I have created an Entity Permission for contact entities. I followed below blog to create the fetchxml:

    https://stoneridgesoftware.com/using-liquid-templates-and-fetchxml-to-retrieve-data-in-a-dynamics-365-online-portal/

    https://colinvermander.com/2018/06/26/dynamics-365-portal-use-liquid-fetchxml-with-paging-cookie/

     

    Also could you please help me in understanding the way how parameters are passing? 

     

    Thanks,

    Amit

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

    Based on the FetchXML query that you mentioned, I think there is something wrong with it.

     

    Firstly, I agree with @OliverRodrigues 's thought almost. The following formula:

    {% assign fullname = request.params.['fullname'] %}
    {% assign cachestring = request.params.['cachestring'] %}

    should be changed into following:

    {% assign fullname = request.params['fullname'] %}
    {% assign cachestring = request.params['cachestring'] %}

    or

    {% assign fullname = request.params.fullname %}
    {% assign cachestring = request.params.cachestring %}

     

    In addition, there is something issue with the <order> attribute. The attribute of the <order> should be bind to the logic name of the column defined in your above <attribute> tag. So the following formula:

    <order attribute='First Name' descending='true' />

    should be changed into below:

    <order attribute='firstname' descending='true' />

     

    You whole FetchXML Query should be like below:

    {% assign fullname = request.params['fullname'] %}
    {% assign cachestring = request.params['cachestring'] %}
    
    {% fetchxml feed %}
    <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
     <entity name='contact'>
     <attribute name='fullname' />
     <attribute name='emailaddress1' />
     <attribute name='contactid' />
     <attribute name='firstname' />
     <order attribute='firstname' descending='true' />
     <filter type='and'>
     <condition attribute='fullname' operator='eq' value='{{fullname}}' /> 
     <condition attribute='fullname' operator='ne' value='{{cachestring}}' /> 
     </filter>
     </entity>
    </fetch>
    {% endfetchxml %}
     [
     {% for item in feed.results.entities %}
     {
     "Contact_id": "{{ item.contactid }}",
     "Contact_Name": "{{ item.fullname }}",
     "Contact_Email": "{{ item.emailaddress1 }}",
     "Contact_First_Name": "{{ item.firstname }}"
     
     }{% unless forloop.last %},{% endunless %}
     {% endfor %}
     ]

     

    For the way how parameters are passing, when you access a web page (in your Portal) which is based on your above FetchXML query through the following URL along with corresponding parameters, for example:

    https://xxxxxx.powerappsportals.com/services/AccountList/?fullname=Steven&cachestring=Liu

    then these appended parameters within the URL would be received by the request.params Liquid expression.

     

    Please check the following article for more details:

    https://docs.microsoft.com/en-us/powerapps/maker/portals/liquid/liquid-objects#request

     

    Best regards,

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @v-xida-msft 

     

    Thanks that resolve me issue but could you please help me with below liquid code, this is not giving me any value for linked entities in JSON (i.e it's blank). I know I am doing some mistake but could you please guide me on this?

     

     

    {% assign contactid = {{user.contactid}} %}
    {% assign cachestring = request.params['cachestring'] %}
    
    {% fetchxml feed %}
    <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
     <entity name='contact'>
     <attribute name='fullname' />
     <attribute name='emailaddress1' />
     <attribute name='contactid' />
     <attribute name='firstname' />
     <order attribute='firstname' descending='true' />
     <filter type='and'>
     <condition attribute='contactid' operator='eq' value='{{contactid}}' /> 
     <condition attribute='fullname' operator='ne' value='{{cachestring}}' /> 
     </filter>
    	<link-entity name='cre08_returntowork_mq' from='cre08_contactlookup_mq' to='contactid' alias='returntoworklink'>
     <attribute name='cre08_returntowork_mqid' />
    	 <attribute name='cre08_firstname' />
     <attribute name='createdon' />
     </link-entity>
     </entity>
    </fetch>
    {% endfetchxml %}
    
     [
     {% for item in feed.results.entities %}
     {
     "Contact_id": "{{ item.contactid }}",
     "Contact_Name": "{{ item.fullname }}",
     "Contact_Email": "{{ item.emailaddress1 }}",
     "Contact_First_Name": "{{ item.firstname }}",
    		"RTW_id": "{{ item['returntoworklink.cre08_returntowork_mqid'].value }}",
    		"RTW_FN": "{{ item['returntoworklink.cre08_firstname'].value }}",
    		"RTW_CreatedOn": "{{ item['returntoworklink.createdon'].value }}",
     
     }{% unless forloop.last %},{% endunless %}
     {% endfor %}
     ]

     

     

     

    I am trying to link the other entities with contact entities. I have a relationship established and  "cre08_contactlookup_mq" this is the lookup field created in "cre08_returntowork_mq" entities. 

     My json is not returning anything for linked entities.

     

    Could you please help in understanding those points and how to make it work?

     

    Thanks,

    Amit

  • v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

    Do you have fix your original issue with the solution I provided above?

     

    If you have fixed your original issue with the solution I provided above, please consider go ahead to click "Accept as Solution" to identify my reply as solution firstly.

     

    For your second issue, I think there is something wrong with your FetchXML query. For the from='cre08_contactlookup_mq' to='cre08_contactlookup_mq' , please check and see if the following article would help in your scenario:

    https://stackoverflow.com/questions/53216249/understanding-link-entity-in-fetchxml

    from always refer to same entity as link-entity node (cre08_contactlookup_mq, the logic name of the LookUp field). to refers to attribute of entity parent node (contactid, Primary Key in your Contact Entity).

    In addition, there are something issue with the attribute value reference in your {% for ... %} expression. Please modify your formula as below:

    {% assign contactid = user.contactid %}
    {% assign cachestring = request.params['cachestring'] %}
    
    {% fetchxml feed %}
    <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
     <entity name='contact'>
     <attribute name='fullname' />
     <attribute name='emailaddress1' />
     <attribute name='contactid' />
     <attribute name='firstname' />
     <order attribute='firstname' descending='true' />
     <filter type='and'>
     <condition attribute='contactid' operator='eq' value='{{contactid}}' /> 
     <condition attribute='fullname' operator='ne' value='{{cachestring}}' /> 
     </filter>
    	<link-entity name='cre08_returntowork_mq' from='cre08_contactlookup_mq' to='contactid' alias='returntoworklink'>
     <attribute name='cre08_returntowork_mqid' />
    	 <attribute name='cre08_firstname' />
     <attribute name='createdon' />
     </link-entity>
     </entity>
    </fetch>
    {% endfetchxml %}
    
     [
     {% for item in feed.results.entities %}
     {
     "Contact_id": "{{ item.contactid }}",
     "Contact_Name": "{{ item.fullname }}",
     "Contact_Email": "{{ item.emailaddress1 }}",
     "Contact_First_Name": "{{ item.firstname }}",
    		"RTW_id": "{{ item['returntoworklink'].cre08_returntowork_mqid.value }}",
    		"RTW_FN": "{{ item['returntoworklink'].cre08_firstname }}",
    		"RTW_CreatedOn": "{{ item['returntoworklink'].createdon }}",
     
     }{% unless forloop.last %},{% endunless %}
     {% endfor %}
     ]

    Please take a try with above solution, check if the issue is solved.

     

    If you still have some issue with this scenario, please consider open a new thread, then we could help you there.

     

    Best regards,

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 47 Super User 2026 Season 1

#2
sannavajjala87 Profile Picture

sannavajjala87 14 Super User 2026 Season 2

#3
SP2019admin Profile Picture

SP2019admin 12

Last 30 days Overall leaderboard