SBX - Search With Button

SBX - Forum Post Title

Getting distinct values from fetchXML using Liquid

Microsoft Dynamics CRM Forum

Usmani asked a question on 9 Jan 2019 5:29 PM

Question Status

Verified

I have a fetchXML that returns data like this 

wondering if I can get distinct group IDs using the same fetchXml by using some filter or otherwise have to write a separate query to get distinct groups?

Reply
Suggested Answer

Hi Usmani,

Use this syntax in your Fetch XML definition.

fetch mapping='logical' distinct='true'>
Reply
Oliver Rodrigues responded on 10 Jan 2019 3:56 AM
My Badges
Verified Answer

do you need the list Groups or you just to render as a group

if you need the list perhaps the easiest way is repeating the fetch only retrieving the GroupId and adding the distinct as per Adrian indication

if your looping and want to render as a group, I would suggest simply storing in a variable the last GroupId and keep verifying if it has changed

worst case scenario you can do 2 fetchs.. one for the groups.. while looping, another fetch filtering by the group.. but this will decrease the performance

Reply
Inogic responded on 10 Jan 2019 4:30 AM
My Badges
Verified Answer

Hi Usmani,

“if I can get distinct group IDs using the same fetchXml by using some filter” – No, you cannot filter it using Fetch XML.

You have to write separate query to get distinct group.

For e.g.:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true ">

 <entity name="group">

   <attribute name="gropupid" />

 </entity>

</fetch>

Hope this helps.

Thanks!

Reply
Oliver Rodrigues responded on 10 Jan 2019 3:56 AM
My Badges
Verified Answer

do you need the list Groups or you just to render as a group

if you need the list perhaps the easiest way is repeating the fetch only retrieving the GroupId and adding the distinct as per Adrian indication

if your looping and want to render as a group, I would suggest simply storing in a variable the last GroupId and keep verifying if it has changed

worst case scenario you can do 2 fetchs.. one for the groups.. while looping, another fetch filtering by the group.. but this will decrease the performance

Reply
Inogic responded on 10 Jan 2019 4:30 AM
My Badges
Verified Answer

Hi Usmani,

“if I can get distinct group IDs using the same fetchXml by using some filter” – No, you cannot filter it using Fetch XML.

You have to write separate query to get distinct group.

For e.g.:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true ">

 <entity name="group">

   <attribute name="gropupid" />

 </entity>

</fetch>

Hope this helps.

Thanks!

Reply
Suggested Answer

Hi Usmani,

Use this syntax in your Fetch XML definition.

fetch mapping='logical' distinct='true'>
Reply

SBX - Two Col Forum

SBX - Migrated JS