Choice field / select a row from HubDB list within a custom module

Is there a way to let the user select an row from a HubDB to select 1 item inside a custom module?

I don’t want the user to copy and past the row ID and make it more simple by letting them select an row from a choice field.

I have seen the following sollution:
https://community.hubspot.com/t5/CMS-Development/Pulling-a-hubdb-column-in-as-a-choice-dropdown/td-p/2267

This will not work since “export_to_template_context=True” does not work with a custom module.

I think there should be a new field to select a row from a selected hubdb to extract data from that row.

Hi Indra,

If I understand correctly, could you not do something like this?

<select>
{% for row in hubdb_table_rows(<tableId or name>, <filterQuery>) %}
<option value="{{ row.hs_id }}">{{ row.<column name> }}</option>
{% endfor %}
</select>

This would give them a select dropdown of all the rows and then you can continue to do it as though they input the ID themselves? (Which ever way you’re doing that)

Unless you need this inside the menu on the edit screen in which case, this wouldn’t work of course

Kind regards,

Sandy

Hi SandyG1,

It’s not for the front-end (visitor) to select an item. It is for the person who created the website/page and for them to select just one row from the HubDB inside a custom module.

Thanks for thinking out loud.

Indra

Hey, did you manage to get it working? I`m searching for the same solution to choose from a testimonial in a table.
Would be amazing. :slightly_smiling_face:
Thanks,
Mike

Need the same Feature for a products table :grinning_face_with_smiling_eyes: Solutions are very welcome-

Thanks

No. Sadly not. Had to create two fields where one let the user select a hubDB and one with a search field so you can search by a row. For example:

{# Text field #}{% set search = module.content.search %}{# HubDB field #}
{% set db = module.content.db %}{# Creat array of employees #}
{% set employees_list = hubdb_table_rows(db) %}{# Creat filtered array of employees by the search term #}
{% set employees = employees_list|selectattr('fullname', 'equalto', search) %}
{# Loop through array #}
{% for employee in employees %}
 {{ employee.fullname }}
{% endfor %}

Idra, did you manage to get it working? I`m searching for the same solution but no luck finding it in the community docs
Greets Eelko

No, sadly not. An alternative version of above I use is using the query param.

{% set db = module.content.db %}
{% set search = module.search %}
{% set queryparam = '&orderBy=order' %}
{% set rows = hubdb_table_rows(db, queryparam) %}

{% if search %}
 {% set queryparam = queryparam~"&name__contains="~search %}
{% endif %}

{# Loop through array #}
{% for row in rows %}
 {{ row.name }}
{% endfor %}

Hubspot just released yesterday a HubDB Row field in Custom Modules. Available to Marketing Hub Professional & Enterprise customers, as well as all CMS Hub Professional & Enterprise customers.

https://www.hubspot.com/product-updates/easily-leverage-hubdb-with-the-new-hubdb-row-field

This is game changing! Super powerful :slightly_smiling_face: thanks for sharing this @alyssamwilie

If you are using a module that has a HubDB row field in it, and then try to programmatically pass a selection from that field inside the module itself, you will likely struggle to figure out how to reference the selection of a hubDB row. Why? Because the page that shows how to reference fields inside modules has every other conceivable field other than a HubDB Row. Has the UbDB Table, but not a row.

Here’s how you pass a hubDB row field selection inside a module that is referencing a table using foreign key:

hubDB_row_selection_field_being_passed_to_custom_module={id={{hubDB_foreign_key_field_in_table.hs_id}}}