SBX - Search With Button

SBX - Forum Post Title

Nested Group By In Liquid Template Dynamics 365 Portal

Microsoft Dynamics CRM Forum

Rawish Kumar asked a question on 20 May 2019 10:58 AM

Question Status

Suggested Answer

Hi Expert,

I am struggling to get nested grouped by data using fetch xml in portal liquid template.

for e.g first group by on Product entity 

Product A, Product B. Within that I have some other lookup and can have different values under the Product A or B.

So the structure Goes like this:

Product A 

   -Type - Raw  

          Manufactured Date : 05/01993

   -Type - ReadyMade

          Manufactured Date : 05/01977

   -Type Raw

          Manufactured Date : 05/07/1930

Should simply be :

Products A ( first Grouby)

     Type - Raw

       Manufactured Date : 05/01993
       Manufactured Date : 05/07/1930

     Type - ReadyMade

       Manufactured Date : 05/01977

Below code is to get the first level grouping - not sure how to proceed with other nested group.

{

fetch xml here///

}

{% assign groups = my_query.results.entities | group_by: 'group by field' }

{% for group in groups %}
 {{ group.key }}
{% for item in group.items %}

Reply
Mahender responded on 20 May 2019 6:46 PM
My Badges

Hi,

Never got such requirement but did you try to use nested loop to access your groups like this

www.siteleaf.com/.../advanced-liquid-group-by

Reply
Rawish Kumar responded on 21 May 2019 1:38 AM

Hi Mahender,

I actually tried it. the first group is fine but for the next one it is just sorting the records. May be i am not doing it right?

{% assign consent_records = my_query.results.entities | group_by: 'product.name' %}     // first group

{% for product in consent_records %}
<h1><u> {{ product.key }}</u></h1>

<script type="text/javascript"> 
console.log(_.groupBy(consent_records,''type)); 
</script>

{% assign group_by_channel = product.items | group_by:'type' %} // second group --- not working
{% for channel in group_by_channel %}

{% for result in channel.items %}

<div name="main-content" style='margin-left: 300px; max-width: 800px;'> 
<h2>Channel: {{ result.type.name }} </h2>
<h2>{{ result.indskr_emailaddress.name }}</h2>
<h2>{{ result.indskr_addressname }} </h2>
<h2>{{ result.indskr_phone }}</h2>
<h2>{{ result.indskr_campaign.name }}</h2>
<button id = '{{result.recordid}}' onclick='executeWorkflow(this.id)'> Opt Out</button>
</div>
Reply
Oliver Rodrigues responded on 21 May 2019 3:55 AM
My Badges
Suggested Answer

is "type" an option set? can you try this:

{% assign group_by_channel = product.items | group_by:'type.value' %} // second group

Reply
Oliver Rodrigues responded on 21 May 2019 3:55 AM
My Badges
Suggested Answer

is "type" an option set? can you try this:

{% assign group_by_channel = product.items | group_by:'type.value' %} // second group

Reply

SBX - Two Col Forum

SBX - Migrated JS