CMS Development

ben-duchy
Colaborador líder

selectattr

resolver

I'm creating a filter that needs to cover an 'or' option, but I can't get it to work beyond the first option. Any ideas what I'm doing wrong?

 

 

{% set table = hubdb_table_rows(xxxxxxx, queryparam) %}

{% set performance = table | selectattr ("plot_status.name","equalto","Exchanged") or ("plot_status.name","equalto","Completed")

{% for row in performance %}
 /* Only seems to display plots that are 'Exchanged' */
{% endfor %}

 

 

0 Me gusta
1 Soluciones aceptada
alyssamwilie
Solución
Experto reconocido | Partner nivel Elite
Experto reconocido | Partner nivel Elite

selectattr

resolver

I'm don't think OR is really possibly with selectattr. Instead you'll want to create variables for each filter and then use |union to combine them (union will deduplicate any common items so if there's an item in both lists it'll only show up once in the for loop).

 

{% set table = hubdb_table_rows(XXXXXX) %}

{% set performance = table|selectattr("plot_status.name","equalto","Exchanged") %}
{% set performance_2 = table|selectattr("plot_status.name","equalto","Completed") %}

{% for row in performance|union(performance_2) %}

{% endfor %}

 

 

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.

Ver la solución en mensaje original publicado

2 Respuestas 2
ben-duchy
Colaborador líder

selectattr

resolver

Hi @alyssamwilie ,

 

Thats a good trick, thank you. I wasn't aware of this filter type.

 

Just to add to this, is it possible to combine even more lists using 'union'? I tried the below but it only returns 1 & 2

{% set performance_1 = table | selectattr("plot_status.name","equalto","Exchanged") %}
{% set performance_2 = table | selectattr("plot_status.name","equalto","Completed") %}
{% set performance_3 = table | rejectattr("sale_type.name","equalto","Affordable") %}
{% set performance_4 = table | selectattr("forecast_year.name","equalto","20/21") %}
{% set performance_5 = table | selectattr("forecast_year.name","equalto","21/22") %}

{% for row in performance_1|union(performance_2,performance_3,performance_4,performance_5) %}

 

Having tried different combinations, I feel that I'm close, but just can't figure out the last part 🤔

0 Me gusta
alyssamwilie
Solución
Experto reconocido | Partner nivel Elite
Experto reconocido | Partner nivel Elite

selectattr

resolver

I'm don't think OR is really possibly with selectattr. Instead you'll want to create variables for each filter and then use |union to combine them (union will deduplicate any common items so if there's an item in both lists it'll only show up once in the for loop).

 

{% set table = hubdb_table_rows(XXXXXX) %}

{% set performance = table|selectattr("plot_status.name","equalto","Exchanged") %}
{% set performance_2 = table|selectattr("plot_status.name","equalto","Completed") %}

{% for row in performance|union(performance_2) %}

{% endfor %}

 

 

If this answer solved your question, please mark it as the solution.

Alyssa Wilie Profile Image

Alyssa Wilie

Web Developerat Lynton

Learn HubL | Get Marketing Insights

HubSpot Elite Solutions Partner
Lynton's HubSpot theme Rubric now available. Click to download.