I try to solve an issue for a custom module as base for a single send email template for transactional emails. So the base idea is to pass on an identifier for a custom object and us on the object stored data to create the email content. Basically its a reminder service for upcomming events.
I tried out three different scenarios:
Query the custom object with a hardcoded query
Everything works fine
Query the custom object with the id on a field in the module
I can fetch the object but not access the properties.
Query the custom object by sending the id on API side as
custom.property.
I can not even fetch the object here.
The three different versions:
Version 1
{% set query_result_without_string_build = crm_object("fomf_content", "ub_event_id=7008", "ub_event_id, brand, id") %}
Version 2
{% set QueryFromField = "ub_event_id=" + module.test_text | string | trim %}
{% set query_result_string_built_from_field = crm_objects('p_fomf_content', "{{ QueryFromField }}", "ub_event_id, brand, id") %}
Version 3
{% set QueryFromSendAPI = "ub_event_id=" ~ custom.ub_event_id | string | trim | replace('\n', '') | replace('\r', '') %}
{% set query_result_string_built_from_custom_parameter = crm_objects('p_fomf_content', "{{ QueryFromSendAPI }}", "ub_event_id, brand, id") %}
I’m just throwing with possible fixes, as it isn’t making any sense.
Also, could you add double quotes around the object_type? That is the only difference between version 1 and version 2 and 3.
Yes it is. 7008 ist just a different id but not the hs record id. I will know the record id on the requesting platform. But this will be achieved later this year - so for now I need to go with the event id.
When I pass on the 4th parameter I get uppercase result on the first result and still nothing on the second result. Quotes do not bring a change.
The issue is somehow based in the query string. When I compare the different query strings the result is:
{% if QueryFromField == QueryFromSendAPI %}
--> NOT EQUAL
{% if QueryFromField == "ub_event_id=7008" %}
--> EQUAL
{% if QueryFromSendAPI == "ub_event_id=7008" %}
--> NOT EQUAL
I just got a possible reason: the value from the custom.template_ub_event_id has not yet been replaced when the crm_object function is called. When you then send the mail, the value is replaced, but this happens later.
To verify this, we have output both values as a base64 string and then calculated them back: