I have created a HubL script that looks at the activities a member has not taken, adds up the dollar value of those activities, and outputs that amount. The script is working in the body of the email, but I am also wanting to put this amount in the subject line. However, when I put the script in the subject line space, the email freezes and I lose all my work in the email. When I create a module and insert that into the subject line, it brings over code and some of that shows up in the email. I’m I going about this wrong or is it not currently possible to do this?
Hello @DianaGomez , a funny thing happened. I did discover what is wrong. That is that the script I provided earlier works ONLY for properties that store a single value.
I set the IF conditional to "==" and a value for property that was multiple checkboxes. So when there was more than one value in property, it didn't render.
What you are supposed to do, and this applies to properties with single or multiple values, is you set a variable, store values in it, separate them by comma and compare that.
Like this:
{% set pref_langs = contact.custom_preferred_language|split(", ") %}
{% if "German" in pref_langs %}
bla bla bla
{% endif %}
You can then add as many if or elif section as you need, in my case the property internal name was custom_preferred_language, and i took its values, split it with filter |split(", ") and then looked for just individual values within the property.
Pretty dumb of me to not think about it earlier, right?
Aside from generating the value and storing it in a property and that then passing into the email subject line as personalization token I didn't find a way around this. I also had something similar, but simpler. I have 1 double opt in email, but 4 different languages on my sites, and since I can have only one double opt in email, I was able to use HubL logic in the email body to display different messages, but not in the email subject line.
What is truly odd is that I added the logic into Subject Line and into Preview text, and it almost looks like its reading the logic, but then defaulting to the default german value of these. Take a look, just for a sake of taking a look.
This is the logic I use for the subject line:
{% if contact.custom_preferred_language == "German" or contact.custom_preferred_language == "German - Switzerland" %} Bestätigen Sie ihre Anmeldung. {% elif contact.custom_preferred_language == "English" %} Confirm your registration. {% elif contact.custom_preferred_language == "Italian" or contact.custom_preferred_language == "Italian - Switzerland" %} Conferma la tua registrazione. {% elif contact.custom_preferred_language == "French" or contact.custom_preferred_language == "French - Switzerland" %} Confirmez votre inscription. {% else %} Bestätigen Sie ihre Anmeldung##. {% endif %}
And when I did a few test sends, I received "Bestätigen Sie ihre Anmeldung##."
See that I added "##" to the default version so I could tell that is the version that comes my way.
I tried waiting and sending DOI email after a few minutes, to see if its a delay problem, but no, even after few minutes even tho I should be getting EN version of the subject line, its still comes in as the default one.
I use the exact same logic for determining the language as in the email body and there is works well. Any ideas what could it be?
I know you posted this question some time ago, and I wanted to check in to see if you've found a solution. If you have, we'd be incredibly grateful if you could share the steps you took – your insights would certainly help others in the community facing a similar challenge! If you're still looking for a solution, please let us know so we can continue our investigation.
Thanks! Diana
HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates. Learn More.
Hello @DianaGomez , a funny thing happened. I did discover what is wrong. That is that the script I provided earlier works ONLY for properties that store a single value.
I set the IF conditional to "==" and a value for property that was multiple checkboxes. So when there was more than one value in property, it didn't render.
What you are supposed to do, and this applies to properties with single or multiple values, is you set a variable, store values in it, separate them by comma and compare that.
Like this:
{% set pref_langs = contact.custom_preferred_language|split(", ") %}
{% if "German" in pref_langs %}
bla bla bla
{% endif %}
You can then add as many if or elif section as you need, in my case the property internal name was custom_preferred_language, and i took its values, split it with filter |split(", ") and then looked for just individual values within the property.
Pretty dumb of me to not think about it earlier, right?
That's a fantastic discovery! Not dumb at all – this is exactly how problem-solving goes with code, especially when dealing with data types and how they're stored. It's easy to overlook how multi-select properties need to be handled differently.
Thanks so much for sharing your findings and the code snippet. 🙂
Best,
Diana
HubSpot’s AI-powered customer agent resolves up to 50% of customer queries instantly, with some customers reaching up to 90% resolution rates. Learn More.