CMS Development

tmcmillan99
Contributor | Elite Partner
Contributor | Elite Partner

Convert url parameter string to integer

SOLVE

I am trying to convert a url parameter to an integer and not having any luck with the correct syntax. The code below shows as an error.

    {% set dealer = '{{ request.query|split("=")|last }}' %}
    {% set filterquery = dealer|int %}
    {% set row = hubdb_table_row(5241455, filterquery) %}

The first line works correctly. I believe the issue is with the second line when I set the filterquery.

Scenario-

I am passing a HubDB row id from another page as a url parameter.

Example - /dealer?id=47948622379

The dealer line above extracts the row id correctly but is a string at this point. Since the row id is an integer in the HubDB table, I am trying to convert it so that my hubdb_table_row line reads it correctly and renders the info from the table that I need. 

 

If I render {{ dealer|int }} on my page, I know it's not converting because it returns a 0.

Any assistance would be greatly appreciated.

 

Thanks,

Terry McMillan

0 Upvotes
1 Accepted solution
tmcmillan99
Solution
Contributor | Elite Partner
Contributor | Elite Partner

Convert url parameter string to integer

SOLVE

I figured out. In case anyone is interested, here is the code that works-

    {% set dealer = '{{ request.query|split("=")|last|trim }}' %}
    {% set dealerval = dealer|render %}
    {% for row in hubdb_table_rows(5241455, 'customerid='~dealerval) %}

 

Terry

View solution in original post

6 Replies 6
tmcmillan99
Contributor | Elite Partner
Contributor | Elite Partner

Convert url parameter string to integer

SOLVE

@dennisedson 

Getting closer on a solution but still need help on syntax. 

The following code does not work:

    {% set dealer = '{{ request.query|split("=")|last|trim }}' %}
    {% set filterquery = "'"~'customerid='~dealer~"'" %}
    {% for row in hubdb_table_rows(5241455, filterquery) %}

The "set filterquery" line produces the following value - 'customerid=01002827-al'

If I copy/paste that value in the hubdb_table_rows line as such:

{% for row in hubdb_table_rows(5241455, 'customerid=01002827-al') %}

It works.

What am I missing in the top code that is causing it not to recognize the filterquery value the same as the actual value? 

I have wasted a ton of time on this and really need to get it resolved. Again, I feel like this should be pretty straight forward and I just can't find the correct syntax.

 

Thanks,

Terry 

tmcmillan99
Solution
Contributor | Elite Partner
Contributor | Elite Partner

Convert url parameter string to integer

SOLVE

I figured out. In case anyone is interested, here is the code that works-

    {% set dealer = '{{ request.query|split("=")|last|trim }}' %}
    {% set dealerval = dealer|render %}
    {% for row in hubdb_table_rows(5241455, 'customerid='~dealerval) %}

 

Terry

dennisedson
HubSpot Product Team
HubSpot Product Team

Convert url parameter string to integer

SOLVE

Love the persistence!

0 Upvotes
tmcmillan99
Contributor | Elite Partner
Contributor | Elite Partner

Convert url parameter string to integer

SOLVE

Does anyone have any ideas? I was thinking this was probably a syntax issue and wouldn't be too difficult to resolve.

 

Option B 

Pass the customerid field in the url parameter since it's a text field. 

How do I tell it to use the "dealer" variable as the value for the customerid column when setting the row?

Something like this code (that doesn't work)-

    {% set dealer = '{{ request.query|split("=")|last }}' %}
    {% set row = hubdb_table_rows(5241455, 'customerid=dealer') %}

 

Thanks,

Terry 

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Convert url parameter string to integer

SOLVE

Maybe @alyssamwilie can help out 🙏

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Convert url parameter string to integer

SOLVE

@Anton , any advice you can add here?