Share Your Work

CFrench
Participant

Help Troubleshoot HubDB Code Issue

SOLVE

Hello!

 

I posted on this last week with some more info (haven't gotten resolution yet), but I'm trying to create a programmable email template that dynamically populates related resources based on HubDB row data for what the contact has already viewed while also excluding that initial resource from the results.

 

It's almost working - so close!

The full code block below works if I hardcode the initial resource variable like:

 

{% set initial_resource = 'https://www.example.com' %}

 

But it does not work the way it's structured in the full code block (testing with a test contact via the email preview tool). Note that I'm setting the initial_resource variable first with a personalization token (c_url) as well vs. simply hardcoding it.

 

If I pretty print the initial_resource varible in the below code snippet, I get something like (again via a contact-specific email preview):

 

(String: https://www.example.com)

 

 So I'm really scratching my head as to why this isn't working:

 

 

{% set resources = hubdb_table_rows(<table_id>) %}

{% for row in resources %}    
    {% set row_url = row.resource_url %}
    {% if row_url is containing initial_resource %}
        {% set c_url = personalization_token("contact.test_url") %}
        {% set initial_resource = curl %}
            {{ initial_resource|pprint }}

        {% set rti = row.resource_type.id %}
        {% set cbi = row.content_bucket.id %}
        {% set queryparam = "" %}

            {% if resource_type != "" %}
            {% set queryparam = queryparam ~ "&resource_type=" ~ rti %}
            {% endif %}

            {% if content_bucket != "" %}
            {% set queryparam = queryparam ~ "&content_bucket=" ~ cbi ~ "&orderBy=count" %}
            {% endif %}    

        {% set rows = hubdb_table_rows(<table_id>, queryparam) %}  

            {% for row in rows|rejectattr('resource_url', 'containing', initial_resource) %}    
                  {% if row_url is containing initial_resource %}
                        <div>{{row.resource_url }} | PASS | {{ rti }} | {{ cbi }}</div>
                      {% else %}
                      FAIL
                  {% endif %}            
            {% endfor %}
    {% endif %}
{% endfor %}

 

 
Any help would be GREATLY appreciated. 

 

Additionally, I'll edit the OP once resolved - just seemed like a higher-level troubleshoot so reposting makes sense.

0 Upvotes
1 Accepted solution
piersg
Solution
Key Advisor

Help Troubleshoot HubDB Code Issue

SOLVE

Hmm... at first glance, I don't think your if statement will evaluate to true because you're using the wrong expression. You need

 

{% if row_url is string_containing initial_resource %}

{% endif %}

 

 

"containing" specifically is to check if a list/array has a value in it. 

 

Edit: also, just to be sure: in the copy pasted code above you've set the initial_resource after the first if statement rather than before it; you can't test a value that doesn't exist yet. Maybe you didn't copy paste that bit of code but I didn't want to assume.

View solution in original post

2 Replies 2
dennisedson
HubSpot Product Team
HubSpot Product Team

Help Troubleshoot HubDB Code Issue

SOLVE

@piersg , could you lend a hand here?

piersg
Solution
Key Advisor

Help Troubleshoot HubDB Code Issue

SOLVE

Hmm... at first glance, I don't think your if statement will evaluate to true because you're using the wrong expression. You need

 

{% if row_url is string_containing initial_resource %}

{% endif %}

 

 

"containing" specifically is to check if a list/array has a value in it. 

 

Edit: also, just to be sure: in the copy pasted code above you've set the initial_resource after the first if statement rather than before it; you can't test a value that doesn't exist yet. Maybe you didn't copy paste that bit of code but I didn't want to assume.