CMS Development

tmcmillan99
Contributor | Elite Partner
Contributor | Elite Partner

Need assistance with correct Hubl code

SOLVE

I need some assistance in determining the correct Hubl code for my scenario below. I am trying to grab part of a request query to use as the customer id in order to pull data from a HubDB table. The code was working correctly but I believe I broke it when adding an additonal parameter (assigned_dealer_v2=) to the requst query to be used in a hidden form field.

 

Example Request Query from the URL-

/dealer?assigned_dealer_v2=Indeco%20Sales&id=00010928-tx

 

My Hubl Code-

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

 

Using the example request query above, I am trying to pull the string after the last "=" sign - 00010928-tx

 

Any ideas on what I have set up wrong?

 

Thanks,

Terry McMillan

0 Upvotes
1 Accepted solution
piersg
Solution
Key Advisor

Need assistance with correct Hubl code

SOLVE

@tmcmillan99 

Your first line setting and assigning the dealer variable is invalid. Remove the quotation marks and remove the brackets. It should be:

 

{% set dealer = request.query|split("=")|last|trim %}

 

View solution in original post

7 Replies 7
piersg
Solution
Key Advisor

Need assistance with correct Hubl code

SOLVE

@tmcmillan99 

Your first line setting and assigning the dealer variable is invalid. Remove the quotation marks and remove the brackets. It should be:

 

{% set dealer = request.query|split("=")|last|trim %}

 

tmcmillan99
Contributor | Elite Partner
Contributor | Elite Partner

Need assistance with correct Hubl code

SOLVE

@piersg That was the issue! Thanks so much for the suggestion. The issue is resolved and the data is displaying correctly now. Much appreciated.

Terry

tmcmillan99
Contributor | Elite Partner
Contributor | Elite Partner

Need assistance with correct Hubl code

SOLVE

Update - I have still not been able to get it to work correctly. I am sure it's going to be something simple. I changed up the code a bit to make it easier to see what value is being rendered if I output it to the page.

New Code-

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

 

If I output {{ dealerval }} on the page, it shows a value of 'customerid=00010928-tx' which is correct and should filter the table to those rows that match.

 

If I manually input the info for dealerval as such:

{% set dealerval ='customerid=00010928-tx' %}

Everything works correctly and it pulls the appropriate info from the row and displays it on the page.

 

Any additional thoughts or suggestions would be greatly appreciated.

Thanks,

Terry

0 Upvotes
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

Need assistance with correct Hubl code

SOLVE

Hey @tmcmillan99 

 

It might be easier to use request.query_dict. This variable breaks all querys into a dictionery thats much easier to use.

 

 

{% set the_query = request.query_dict %}

{% set dealer = the_query.id %}

 

With this method you can also handle situations when the query isn't present.

{% if !the_query.id %}
  Somthing went wrong
{% endif %}

 

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
tmcmillan99
Contributor | Elite Partner
Contributor | Elite Partner

Need assistance with correct Hubl code

SOLVE

Awesome @Kevin-C.

Thanks for the suggestion! I have not seen that variable before so I will definitely look into more. 

 

miljkovicmisa
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Need assistance with correct Hubl code

SOLVE

Hello @tmcmillan99 , can you output the dealer id with a {{dealerval}} so that we can see that the correct value is pulled off the request query?
I used your exact code and it does indeed pull the "00010928-tx" value.
Maybe the issue is with the hubdb.

tmcmillan99
Contributor | Elite Partner
Contributor | Elite Partner

Need assistance with correct Hubl code

SOLVE

@miljkovicmisa Thanks for the reply back and confirmation that the code is working as it should. I have not looked at the HubDB table yet. It was recently updated by the client so that will definitely be my next step.

Thanks for the assistance.

Terry

0 Upvotes