cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
shahriat
Helper II
Helper II

How to use fetchxml in portal and read option set and related entity atrributes?

I have following fetch xml code:

 

{% fetchxml contacts %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="contact">
<attribute name="firstname" />
<attribute name="lastname" />
<attribute name="fax" />
<attribute name="address1_line1" />
<attribute name="address1_line2" />
<attribute name="address1_stateorprovince" />
<attribute name="address1_country" />
<attribute name="emailaddress1" />
<attribute name="gendercode" />
<attribute name="birthdate" />
<attribute name="donotsendmm" />
<attribute name="preferredcontactmethodcode" />
<attribute name="donotemail" />
<attribute name="followemail" />
<attribute name="donotbulkemail" />
<attribute name="donotphone" />
<attribute name="donotfax" />
<attribute name="donotpostalmail" />
<order attribute="fullname" descending="false" />
 
<link-entity name="account" from="primarycontactid" to="contactid" link-type="inner" alias="ab">
<attribute name="name" />
</link-entity>
<link-entity name="new_relatedentity" from="new_relatedentityid" to="new_isstest" link-type="inner" alias="ac">
<attribute name="new_name"/>
</link-entity>
</entity>
</fetch>
{% endfetchxml %}

{% assign contact= contacts.results.entities[0] %}
 
I want to show option set value and reference entity name like:
 
{{contact.preferredcontactmethodcode@OData.Community.Display.V1.FormattedValue}}  //nothing showing
{{contact.ab.name}} //nothing showing
{{contact.ac.new_name}} //nothing showing
 
but none of them work.
 
not sure my syntax is correct or not in portal template.
 
any advice?
1 ACCEPTED SOLUTION

Accepted Solutions
justinburch
Microsoft
Microsoft

Hi @shahriat,

Your syntax is a bit off and your related contact is not pulling in a valid contact value (I believe). Try the following:

{% fetchxml contacts %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="contact">
<attribute name="firstname" />
<attribute name="lastname" />
<attribute name="fax" />
<attribute name="address1_line1" />
<attribute name="address1_line2" />
<attribute name="address1_stateorprovince" />
<attribute name="address1_country" />
<attribute name="emailaddress1" />
<attribute name="gendercode" />
<attribute name="birthdate" />
<attribute name="donotsendmm" />
<attribute name="preferredcontactmethodcode" />
<attribute name="donotemail" />
<attribute name="followemail" />
<attribute name="donotbulkemail" />
<attribute name="donotphone" />
<attribute name="donotfax" />
<attribute name="donotpostalmail" />
<order attribute="fullname" descending="false" />
 
<link-entity name="account" from="primarycontactid" to="contactid" link-type="inner" alias="ab">
<attribute name="fullname" />
</link-entity>
<link-entity name="new_relatedentity" from="new_relatedentityid" to="new_isstest" link-type="inner" alias="ac">
<attribute name="new_name"/>
</link-entity>
</entity>
</fetch>
{% endfetchxml %}

{% if contacts.results.entities.size > 0 %}
Contact with AB and AC found!
{% assign contact = contacts.results.entities | first %}
AB Name: {{ contact.ab.fullname }}
AC Name: {{ contact.ac.new_name }}
Preferred Method of Contact: {{ contact.preferredcontactmethodcode.label }} ({{ contact.preferredcontactmethodcode.value }})
{% else %}
No contacts found
{% endif %}

Note that it won't return any results if there is no contact with both AB and AC related records, and both entities need to have proper Entity Permissions setup.

 

View solution in original post

4 REPLIES 4
justinburch
Microsoft
Microsoft

Hi @shahriat,

Your syntax is a bit off and your related contact is not pulling in a valid contact value (I believe). Try the following:

{% fetchxml contacts %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="contact">
<attribute name="firstname" />
<attribute name="lastname" />
<attribute name="fax" />
<attribute name="address1_line1" />
<attribute name="address1_line2" />
<attribute name="address1_stateorprovince" />
<attribute name="address1_country" />
<attribute name="emailaddress1" />
<attribute name="gendercode" />
<attribute name="birthdate" />
<attribute name="donotsendmm" />
<attribute name="preferredcontactmethodcode" />
<attribute name="donotemail" />
<attribute name="followemail" />
<attribute name="donotbulkemail" />
<attribute name="donotphone" />
<attribute name="donotfax" />
<attribute name="donotpostalmail" />
<order attribute="fullname" descending="false" />
 
<link-entity name="account" from="primarycontactid" to="contactid" link-type="inner" alias="ab">
<attribute name="fullname" />
</link-entity>
<link-entity name="new_relatedentity" from="new_relatedentityid" to="new_isstest" link-type="inner" alias="ac">
<attribute name="new_name"/>
</link-entity>
</entity>
</fetch>
{% endfetchxml %}

{% if contacts.results.entities.size > 0 %}
Contact with AB and AC found!
{% assign contact = contacts.results.entities | first %}
AB Name: {{ contact.ab.fullname }}
AC Name: {{ contact.ac.new_name }}
Preferred Method of Contact: {{ contact.preferredcontactmethodcode.label }} ({{ contact.preferredcontactmethodcode.value }})
{% else %}
No contacts found
{% endif %}

Note that it won't return any results if there is no contact with both AB and AC related records, and both entities need to have proper Entity Permissions setup.

 

View solution in original post

Hi Justin,

Thanks a lot for your reply.

 

I have implemented your suggested solution that works but value doesn't show for two options type field like {{contact.donotphone.label}}.

 

what could be syntax to show two option field value like donotphone?

I have resolved the issue. Two option works as boolean type. So it works fine. 

VyasVaishali
Regular Visitor

Hi,

You can read my blog on how you can access column(field) of different data type using FetchXML and liquid in PowerApps Portal.

 

Part 1: https://vblogs.in/fetchxml-in-powerapps-portal/

Part 2: https://vblogs.in/fetchxml-in-powerapps-portal-part-2/ 

 

Thank You.

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,428)