CMS Development

NWestby
Member

Personalization tokens with associated objects in emails

SOLVE

How can I show information from a custom object's associated record within an email? I believe I need to use personalization tokens, but the only values I can see are the properties of the custom object, not for the associated custom object.

 

For example, I can get the expiration date of a "reservation" with the following and have it render in an email. Expriation date is a property on this custom object. So I can see it.

{{ personalization_token('p9096463_reservation.expiration_date', 'default value') }}

 

However, if I want to get the Hours of Operation(an associated custom object) I'm not seeing anything. Ideally I was hoping for

personalization_token('p9096463_reservation.hours_of_operation')

But this does not appear on the list of personalized tokens.

 

Is there anyway I can show an associated custom object's value within an email?

 

Thanks! 

0 Upvotes
1 Accepted solution
NWestby
Solution
Member

Personalization tokens with associated objects in emails

SOLVE

EDIT: Note that it seemed to be possible with my previous answer, but that's not true. You have to hard code the object ID for it to work. It seems you can't pass the ID as fetched from "personalization_token" to "crm_assocations".

 

ORIGINAL MESSAGE BELOW:

It turns out this is possible thanks to "crm_assocations". It goes a bit like this:

 

{% set facility_hours = crm_associations(57297248, 'USER_DEFINED', 46) %}
<p>
  {{ facility_hours }}
</p>
<p>
  {% for item in facility_hours.results %}
    <p>
      {{ item.day_of_week }}
    </p>
  {% endfor %}
</p>

 

 

The first parameter is the current reservation ID (reservations being a custom object schema we created). The third parameter is an ID telling HubSpot which type of object to look for (in this case, the hours of operation). The second parameter, which doesn't seem to be currently documented, says that this is a user-defined custom object.

 

I'm not sure there's a straightforward way to find the third parameter (can be done with React tools by inspecting the data in the HubSpot UI for the custom object detail page), but the first parameter can be figured out with the "personalization_token" function.

View solution in original post

dennisedson
Community Manager
Community Manager

Personalization tokens with associated objects in emails

SOLVE

Hello @NWestby 

I am not sure if that is possible 🤔

@Bryantworks , @piersg have either of you attempted this?

 

Thanks,

Dennis




HubSpot Community Developer ShowMake sure to subscribe to our YouTube channel
where you can find the HubSpot Community Developer Show
0 Upvotes
NWestby
Solution
Member

Personalization tokens with associated objects in emails

SOLVE

EDIT: Note that it seemed to be possible with my previous answer, but that's not true. You have to hard code the object ID for it to work. It seems you can't pass the ID as fetched from "personalization_token" to "crm_assocations".

 

ORIGINAL MESSAGE BELOW:

It turns out this is possible thanks to "crm_assocations". It goes a bit like this:

 

{% set facility_hours = crm_associations(57297248, 'USER_DEFINED', 46) %}
<p>
  {{ facility_hours }}
</p>
<p>
  {% for item in facility_hours.results %}
    <p>
      {{ item.day_of_week }}
    </p>
  {% endfor %}
</p>

 

 

The first parameter is the current reservation ID (reservations being a custom object schema we created). The third parameter is an ID telling HubSpot which type of object to look for (in this case, the hours of operation). The second parameter, which doesn't seem to be currently documented, says that this is a user-defined custom object.

 

I'm not sure there's a straightforward way to find the third parameter (can be done with React tools by inspecting the data in the HubSpot UI for the custom object detail page), but the first parameter can be figured out with the "personalization_token" function.

JOHara
Participant

Personalization tokens with associated objects in emails

SOLVE

You would be able to retrive the object without hard coding the value if you make use of the Programmable Email Beta . This will allow you to pass some other property instead. For example

{% set facility_id = p12345_facility.hs_object_id %}
{% set facility_hours = crm_associations(facility_id, 'USER_DEFINED', 46) %}