CMS Development

Mohva
Participante

Problem when filtering a HubDB query with a custom module field

resolver

Hi,

 

I'm trying to add a filter to a HubDB query, using the content from a text field in a cusom module.

 

In my custom module, I have the following code, wich works fine:

 

{% for row in hubdb_table_rows(table_id,"&partner__eq=3") %}
Print Something
{%endfor%}

 

I want the "3" to be dinamically set on each different page. For that, I'm using a Text Field on the Custom module.

 

I would expect that something like this would work:

{% for row in hubdb_table_rows(table_id,"&partner__eq="~widget.partner_number) %}
Print Something
{%endfor%}

 

But this, or any variant form of concatenating the string with the field content, gives me the same result:

"The following validation error was found:"

With no extra detail.

 

I even tried to do domething like this, wich works:

{% set partner_number="3"%}
{% set pre_filter="&partner__eq="%}
{% set filter= pre_filter ~ partner_number %}

{% for row in hubdb_table_rows(155348,filter) %}

 

But when I change the "3" with widget.partner_number, it gives the same error.

 

Does anyone has any idea what it might be the problem?

 

Thanks,

 

 

 

 

1 Solução aceita
nickdeckerdevs
Solução
Colaborador(a) | Parceiro Diamante
Colaborador(a) | Parceiro Diamante

Problem when filtering a HubDB query with a custom module field

resolver

I set up all my queries outside of that for loop, like you are showing at the bottom.

{% set queryparams = "" %} 
{% if request.query_dict.fname %}
{% set queryparams = queryparams ~ "&fname="~request.query_dict.fname|title|urlencode %}
{% endif %} 

 

Exibir solução no post original

5 Respostas 5
nickdeckerdevs
Solução
Colaborador(a) | Parceiro Diamante
Colaborador(a) | Parceiro Diamante

Problem when filtering a HubDB query with a custom module field

resolver

I set up all my queries outside of that for loop, like you are showing at the bottom.

{% set queryparams = "" %} 
{% if request.query_dict.fname %}
{% set queryparams = queryparams ~ "&fname="~request.query_dict.fname|title|urlencode %}
{% endif %} 

 

adriancblack
Participante | Parceiro
Participante | Parceiro

Problem when filtering a HubDB query with a custom module field

resolver

How do you acheave this but with THE TABLE ID being dinamic?

 

ie:

 

{% set queryparam = "&orderBy=order" %}

{% set tableid = "widget.table_id" %} /* table id can change from page to page */

{% for row in hubdb_table_rows( tableid , queryparam )%}

 content here
{% endfor %}

0 Avaliação positiva
Mohva
Participante

Problem when filtering a HubDB query with a custom module field

resolver

In my case, the table_id is always the same.

 

I can imagine different ways you can make it dynamic. If the change occurs in the page level, you can create a property on a Custom Module that allows you to set the related table_id for each page. 

 

If you need to be dynamic within the page, you will have to put a Hubl variable with all the tables ids available and make your algorithm from there.

 

Or if your tables will be changin, maybe is better to use te REST API and process the tables using Javascript (http://developers.hubspot.com/docs/methods/hubdb/get_tables).

 

But in that case, you have to be more carefull since you'll have to go throught authentication, so you probably don't wan't to expose that to the general public.

 

Hope that helps.

0 Avaliação positiva
Mohva
Participante

Problem when filtering a HubDB query with a custom module field

resolver

Not sure what did the trick, but it worked like a charm.

Here is the code I implemented, using yours as base:

 

{% set queryparams = "" %}
{% if widget.partner_number %}
{% set queryparams = queryparams ~ "&partner__eq="~widget.partner_number|title|urlencode %}
{% endif %}

{% for row in hubdb_table_rows(tableid, queryparams ) %}

Print Something

{% endfor %}

 

Thanks.

 

 

boulter
Equipe de Produto da HubSpot
Equipe de Produto da HubSpot

Problem when filtering a HubDB query with a custom module field

resolver

I'm glad you got it working. A few tips:

 

  • "__eq" is the default comparison operator, so you can just use "partner=".
  • You don't need to start the query with an '&'. It should still work, but it's unnecessary.
  • If partner_number is really just a number, you don't the title or urlencode filters.
  • Nick is correct in that you do have to build the query string before the hubdb_rable_rows call.