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

SOLVE
Indra
Top Contributor | Diamond Partner

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...

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.


Bureau Vet

Did my post solve your question? Help the community by marking it as a solution
1 Accepted solution

Accepted Solutions
amwilie
Solution
Key Advisor | Elite Partner

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

border

Alyssa Wilie

Web Developer at LyntonWeb

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

View solution in original post

10 Replies 10
SandyG1
Contributor | Partner

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

0 Upvotes
Indra
Top Contributor | Diamond Partner

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


Bureau Vet

Did my post solve your question? Help the community by marking it as a solution
0 Upvotes
MikeBeatwoot
Participant

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. 🙂

Thanks,
Mike

0 Upvotes
Schascha
Participant

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

Thanks

0 Upvotes
Indra
Top Contributor | Diamond Partner

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 %}

Bureau Vet

Did my post solve your question? Help the community by marking it as a solution
0 Upvotes
Eelko
Participant | Partner

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

0 Upvotes
Indra
Top Contributor | Diamond Partner

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 %}

Bureau Vet

Did my post solve your question? Help the community by marking it as a solution
0 Upvotes
amwilie
Solution
Key Advisor | Elite Partner

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

border

Alyssa Wilie

Web Developer at LyntonWeb

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

View solution in original post

SandyG1
Contributor | Partner

This is game changing! Super powerful 🙂  thanks for sharing this @amwilie 

 

CP-BWG
Contributor

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}}}