CMS Development

RepreZenTed
Colaborador(a)

"Invalid id: null" when invoking crm_associations() function with a variable argument

resolver

I'm trying to get the following code to work, but there seems to be a problem passing contact_id as the first argument to the HUBL crm_associations() function. 

 

{% set contact_id = contact.hs_object_id %}
{% set deals = crm_associations(contact_id, 4) %} 
  <p>
    There are {{deals.results|length}} deals for {{contact.firstname}} {{contact.lastname}} (id # {{contactID}} ):
  </p>
<ul>
{% for deal in deals.results %}
    <li>{{ deal.dealname }}</li>
{% endfor %}
</ul>

In the editor, it shows "invalid id: null" and when I preview an email based on this template, the deals variable is empty or null. If I replace that first argument with a literal contact ID, it works fine. But that won't work for my purposes; I need it to be dynamic.

 

How can I pass a variable expression as the function argument?

 

1 Solução aceita
RepreZenTed
Solução
Colaborador(a)

"Invalid id: null" when invoking crm_associations() function with a variable argument

resolver

Here are my follow-up questions and the answers I received from Ben in Hubspot technical support: 

 

QUESTIONS

 

1. What is request_contact? How is it different from contact, and how does it relate to email?

 

The "Hubl supported variables" reference page says only that request_contact is "A dictionary containing data about the requested contact."

https://designers.hubspot.com/docs/hubl/hubl-supported-variables

What does "requested contact" mean? Is it really "requested contact" or is it "requesting contact", meaning the current user contact as determined by a form submission (or by a cookie from a previous form submission)? If that's a correct interpretation, then is it also correct to say that the request_contact concept is extended (or repurposed) in the email context, to mean the email recipient contact?

Is this explained anywhere...?

 

2. What is contact_vid? How is it different from the hs_object_id property of a contact object?

 

It's shown in a code example here, but not explained:
https://designers.hubspot.com/docs/tutorials/crm-data-for-cms-pages

It doesn't appear in the properties UI. Why not?
https://app.hubspot.com/property-settings/597611

It's not mentioned in the HubL reference page.
https://designers.hubspot.com/docs/hubl/hubl-supported-variables

The API page on contacts explains that it's the internal ID of a contact. In that case, would hs_object_id return the same value?
https://developers.hubspot.com/docs/methods/contacts/contacts-overview

This page explains that 'vid' stands for visitor ID, which is helpful information:
https://developers.hubspot.com/docs/methods/contacts/get_contact

 

3. Why is it that request_contact.contact_vid works, but contact.hs_object_id doesn't?

It would help to understand, at a deeper level, what is the intended purpose and meaning of 'contact' as distinct from 'request_contact'. I assume the difference in behavior can be better explained if we understand how these two concepts are different. But I have not found anything that explains this.

 

ANSWERS

 

Ben writes:

 

The reason why the variables are not treated the same way when calling them within a functions argument is likely due in part to the dictionary structure and in part due to the data type.

 

For information on what HubL data is available to use, you can reference this page. By using the Developer info page, you can see all of the data that is available to HubL. Searching here, you can see the top-level variables request_contact and contact. In HubL, these are what we call dictionaries, because they’re variables that contain key/value pairs.

 

It looks like the contact dictionary is duplicated inside of the request_contact dictionary. If you do a search on this page: https://designers.hubspot.com/docs/hubl/hubl-supported-variables, we do have request_contact documented. A dictionary containing data about the requested contact. We also have contact documented.

 

This variable is a dictionary that stores contact personalization properties for a known contact. Properties can be accessed from this dicionary, by adding a period and the property name. For example, contact.firstname would print the first name of a contact. so I think to answer your first question, request_contact is a dictionary that includes the contact dictionary, but then also includes additional info about the contact.

 

For your second question, contact_vid and hs_object_id are going to be the same. VID just refers visitor ID. it’s the ID that we use to identify a contact record. Contacts are a type of CRM object. As for why these two properties are named differently in different places, It is likely just because of the naming convention used in whichever tool is outputting the dictionary.

 

Your third question is a little more difficult to answer as it relates to some specific use cases of HubL within Emails as opposed to its use in the CRM. We’ve made some improvements to HubL over the years to include more functionality in email, though this may have lead to some unforeseen issues. This could be related to the fact that contact.hs_object_id is a string, whereas request_contact.contact_vid is a long. It could also be the crm_assocations()function is trying to run before it has access to the contact dictionary.

 OK, so I still wonder why contact and request_contact are two different variables, with different behaviors. I don't understand the explanation that request_contact is "a dictionary containing data about the requested contact." The phrase "requested contact" doesn't mean anything in the context of an email, and it doesn't explain how request_contact is different from contact

 

But I will leave it here for now, since I have a working solution with request_contact.

Exibir solução no post original

4 Respostas 4
RepreZenTed
Colaborador(a)

"Invalid id: null" when invoking crm_associations() function with a variable argument

resolver

Cross-reference to another issue, apparently related, and Slack discussions: 

 

I suspect that there's one general limitation that prevents the use of email contact properties ("personalization tokens") in {% if %},{% for %}, and {% set %} statements. If my hunch is correct, the use of the contact variable is limited to simple placeholders in the "compiled" template; you can't use contact properties in any dynamic statements. 

 

This is disappointing. I'd really to see this fixed. 

 

In the meantime, it would be helpful if Hubspot could confirm or correct my understanding of this. And *very* helpful to update the reference pages that describe  set, forand any other statements affected by this design limitation. As of now, AFAIK, the limitation is only documented on the if statement page. It would have saved me a lot of time if I had known about this!

RepreZenTed
Colaborador(a)

"Invalid id: null" when invoking crm_associations() function with a variable argument

resolver

Through Hubspot Support, I got the suggestion to use request_contact.contact_vid instead of contact.hs_object_id

 

This works, but I really don't understand why, and have asked for some clarification on this. I'll post back, and hopefully mark this issue as solved, once I can provide a better explanation.

RepreZenTed
Solução
Colaborador(a)

"Invalid id: null" when invoking crm_associations() function with a variable argument

resolver

Here are my follow-up questions and the answers I received from Ben in Hubspot technical support: 

 

QUESTIONS

 

1. What is request_contact? How is it different from contact, and how does it relate to email?

 

The "Hubl supported variables" reference page says only that request_contact is "A dictionary containing data about the requested contact."

https://designers.hubspot.com/docs/hubl/hubl-supported-variables

What does "requested contact" mean? Is it really "requested contact" or is it "requesting contact", meaning the current user contact as determined by a form submission (or by a cookie from a previous form submission)? If that's a correct interpretation, then is it also correct to say that the request_contact concept is extended (or repurposed) in the email context, to mean the email recipient contact?

Is this explained anywhere...?

 

2. What is contact_vid? How is it different from the hs_object_id property of a contact object?

 

It's shown in a code example here, but not explained:
https://designers.hubspot.com/docs/tutorials/crm-data-for-cms-pages

It doesn't appear in the properties UI. Why not?
https://app.hubspot.com/property-settings/597611

It's not mentioned in the HubL reference page.
https://designers.hubspot.com/docs/hubl/hubl-supported-variables

The API page on contacts explains that it's the internal ID of a contact. In that case, would hs_object_id return the same value?
https://developers.hubspot.com/docs/methods/contacts/contacts-overview

This page explains that 'vid' stands for visitor ID, which is helpful information:
https://developers.hubspot.com/docs/methods/contacts/get_contact

 

3. Why is it that request_contact.contact_vid works, but contact.hs_object_id doesn't?

It would help to understand, at a deeper level, what is the intended purpose and meaning of 'contact' as distinct from 'request_contact'. I assume the difference in behavior can be better explained if we understand how these two concepts are different. But I have not found anything that explains this.

 

ANSWERS

 

Ben writes:

 

The reason why the variables are not treated the same way when calling them within a functions argument is likely due in part to the dictionary structure and in part due to the data type.

 

For information on what HubL data is available to use, you can reference this page. By using the Developer info page, you can see all of the data that is available to HubL. Searching here, you can see the top-level variables request_contact and contact. In HubL, these are what we call dictionaries, because they’re variables that contain key/value pairs.

 

It looks like the contact dictionary is duplicated inside of the request_contact dictionary. If you do a search on this page: https://designers.hubspot.com/docs/hubl/hubl-supported-variables, we do have request_contact documented. A dictionary containing data about the requested contact. We also have contact documented.

 

This variable is a dictionary that stores contact personalization properties for a known contact. Properties can be accessed from this dicionary, by adding a period and the property name. For example, contact.firstname would print the first name of a contact. so I think to answer your first question, request_contact is a dictionary that includes the contact dictionary, but then also includes additional info about the contact.

 

For your second question, contact_vid and hs_object_id are going to be the same. VID just refers visitor ID. it’s the ID that we use to identify a contact record. Contacts are a type of CRM object. As for why these two properties are named differently in different places, It is likely just because of the naming convention used in whichever tool is outputting the dictionary.

 

Your third question is a little more difficult to answer as it relates to some specific use cases of HubL within Emails as opposed to its use in the CRM. We’ve made some improvements to HubL over the years to include more functionality in email, though this may have lead to some unforeseen issues. This could be related to the fact that contact.hs_object_id is a string, whereas request_contact.contact_vid is a long. It could also be the crm_assocations()function is trying to run before it has access to the contact dictionary.

 OK, so I still wonder why contact and request_contact are two different variables, with different behaviors. I don't understand the explanation that request_contact is "a dictionary containing data about the requested contact." The phrase "requested contact" doesn't mean anything in the context of an email, and it doesn't explain how request_contact is different from contact

 

But I will leave it here for now, since I have a working solution with request_contact.

jennysowyrda
Gerente da Comunidade
Gerente da Comunidade

"Invalid id: null" when invoking crm_associations() function with a variable argument

resolver

Thanks for sharing @RepreZenTed

0 Avaliação positiva