CMS Development

RogerCB
Member

Dynamic Product Recommendations Based on Deals – Workflow

Hey there!


We're trying to create a workflow in HubSpot that allows us to send product recommendations based on a common attribute between deals and products, but we're struggling to implement it.


Workflow Objective:

Type: Deal-based.
The goal is to send an email with a list of 3 recommended products, which should be dynamic and depend on the deal in question.
Example: For Deal A, the recommended products could be 1, 2, 3; for Deal B: 5, 6, 7. Deal A matches with Product 1,2,3 by the custom property, same for Deal B and products 5,6,7

 

Current Setup:

Deals have a custom property called "creator_slug."
Products also have the custom property "creator_slug.
We want to link the products to the deals using this property and display the top 3 products

 

Current Progress:

We've tried several approaches, but the closest we've come to a solution is by creating a custom template in Content > Design Manager with the following code:

 

{% set key = "limit=3&creator_slug__eq=" ~ deal.creator_slug %}
{{ key }} -- the string is evaluated correctly and is valid
{% set objects = crm_objects("product", key, "name,creator_slug") %}
{% for product in objects.results %}
<p>{{ product.name }} - {{product.creator_slug}}</p>
{% endfor %}


The issue we're facing is that when we try to use the dynamic key value to filter the products, no results are returned. It seems like crm_objects is evaluated before the key is generated, so the query doesn't return any results. However, when we switch the query to a static value like:

crm_objects("product", "limit=3&creator_slug__eq=myslug", "name,creator_slug")


we do get the correct products.

 

Is there any way we can use the dynamic property in the query to get the products that match the current deal's "creator_slug"?

 

Could you guide us on how to achieve this? If there's any other alternative approach to achieve the same goal, we'd love to hear about it, as we're a bit stuck at the moment.

 

Thanks a lot for your help!

0 Upvotes
2 Replies 2
AddaxLab
Member

Dynamic Product Recommendations Based on Deals – Workflow

In your current approach, the key is dynamically built using the deal.creator_slug, but when you pass it into crm_objects, it seems the variable might need to be evaluated properly due to how HubSpot handles the order of evaluation in its server-side rendering.

So, you can try to assign the creator_slug to a separate variable like this:

{% set creator_slug = deal.creator_slug %}
{% set query_string = "limit=3&creator_slug__eq=" ~ creator_slug %}
{% set objects = crm_objects("product", query_string, "name,creator_slug") %}

{% for product in objects.results %}
<p>{{ product.name }} - {{ product.creator_slug }}</p>
{% endfor %}

Also, you can debug your approach printing the final query_string:
<p>{{ query_string }}</p>

AddaxLab_1-1726236997438.png

 

0 Upvotes
RogerCB
Member

Dynamic Product Recommendations Based on Deals – Workflow

Tried that as well, however we have the same problem.

We are "Testing" it by previewing the email, selecting a deal and a contact and checking the results.

It feels like the crm_objects doesnt "rerender" once the deal has been selected. 

0 Upvotes