<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Only return HubDB multi-select and select options if active on row item in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Only-return-HubDB-multi-select-and-select-options-if-active-on/m-p/838118#M35531</link>
    <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/46249"&gt;@marenhogan&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;One way would be instead of accessing the options of the columns directly, to filter out all used values in the rows of the hubdb:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{# your hubdb table id #}
{% set table_id = 6934042 %}

{# name of the (multi)select column #}
{% set multiselect_column_name = "type" %}

{# get all hubdb rows #}
{% set table = hubdb_table_rows(table_id) %}

{# remove rows that have no value and select the column #}
{% set table_filtered_multiselect = table|selectattr(multiselect_column_name)|map(multiselect_column_name) %}

{# get all the used options from the rows #}
{% set used_multiselect_options = [] %}
{% for item in table_filtered_multiselect %}
    {% for subitem in item %}
        {% do used_multiselect_options.append(subitem) %}
    {% endfor %}
{% endfor %}

{# remove duplicates and sort the options #}
{% set used_multiselect_options = used_multiselect_options|unique|sort(False, False, "order") %}

{{ used_multiselect_options|pprint }}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Aug 2023 11:01:32 GMT</pubDate>
    <dc:creator>paradummy</dc:creator>
    <dc:date>2023-08-22T11:01:32Z</dc:date>
    <item>
      <title>Only return HubDB multi-select and select options if active on row item</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Only-return-HubDB-multi-select-and-select-options-if-active-on/m-p/836347#M35478</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;I was having trouble finding an answer to this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a HubDB table with a few columns. One of these columns is a multiselect and another is a select column.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looping through on the front-end to show the options in the multiselect and select columns, but I only want those output if there is a row entry that has been assigned to one of those items.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example, in my select column, I have&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Blog Posts&lt;/LI&gt;
&lt;LI&gt;Case Studies&lt;/LI&gt;
&lt;LI&gt;ROI Calculators&lt;/LI&gt;
&lt;LI&gt;Survey Results&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;On the front-end, it's showing all 4 of those options, but I only have row items assigned to 3 of them. Here is my output code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; {% set tab2 = hubdb_table_column(6934042, "type") %}&lt;BR /&gt;{% if tab2 %}&lt;BR /&gt;&amp;lt;ul class="u3m-filtered-content__multi-filter__ul fs_industries_type"&amp;gt;&lt;BR /&gt;&amp;lt;li&amp;gt;&amp;lt;a data-filter="all"&amp;gt;All Content Types&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;BR /&gt;{% for cat2 in tab2.options %}&lt;BR /&gt;&amp;lt;li&amp;gt;&lt;BR /&gt;&amp;lt;a data-filter=".{{ cat2.name|lower|replace(' ','-')|replace('/','-')|replace('&amp;amp;','-')|replace(',','-') }}"&amp;gt;{{ cat2.name }}&amp;lt;/a&amp;gt;&lt;BR /&gt;&amp;lt;/li&amp;gt; &lt;BR /&gt;{% endfor %}&lt;BR /&gt;&amp;lt;/ul&amp;gt;&lt;/PRE&gt;
&lt;P&gt;How can I only show active ones?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 22:02:26 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Only-return-HubDB-multi-select-and-select-options-if-active-on/m-p/836347#M35478</guid>
      <dc:creator>marenhogan</dc:creator>
      <dc:date>2023-08-17T22:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Only return HubDB multi-select and select options if active on row item</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Only-return-HubDB-multi-select-and-select-options-if-active-on/m-p/836671#M35489</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/46249"&gt;@marenhogan&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; Thanks for your question. Your clear description and code examples are very helpful for our community.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hey,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/91608"&gt;@alyssamwilie&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/78983"&gt;@Indra&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/66301"&gt;@Bryantworks&lt;/a&gt;, have you worked on anything similar in your recent projects?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for taking a look! — Jaycee&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 15:03:37 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Only-return-HubDB-multi-select-and-select-options-if-active-on/m-p/836671#M35489</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2023-08-18T15:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Only return HubDB multi-select and select options if active on row item</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Only-return-HubDB-multi-select-and-select-options-if-active-on/m-p/838118#M35531</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/46249"&gt;@marenhogan&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;One way would be instead of accessing the options of the columns directly, to filter out all used values in the rows of the hubdb:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{# your hubdb table id #}
{% set table_id = 6934042 %}

{# name of the (multi)select column #}
{% set multiselect_column_name = "type" %}

{# get all hubdb rows #}
{% set table = hubdb_table_rows(table_id) %}

{# remove rows that have no value and select the column #}
{% set table_filtered_multiselect = table|selectattr(multiselect_column_name)|map(multiselect_column_name) %}

{# get all the used options from the rows #}
{% set used_multiselect_options = [] %}
{% for item in table_filtered_multiselect %}
    {% for subitem in item %}
        {% do used_multiselect_options.append(subitem) %}
    {% endfor %}
{% endfor %}

{# remove duplicates and sort the options #}
{% set used_multiselect_options = used_multiselect_options|unique|sort(False, False, "order") %}

{{ used_multiselect_options|pprint }}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2023 11:01:32 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Only-return-HubDB-multi-select-and-select-options-if-active-on/m-p/838118#M35531</guid>
      <dc:creator>paradummy</dc:creator>
      <dc:date>2023-08-22T11:01:32Z</dc:date>
    </item>
  </channel>
</rss>

