Can't get HUBL Split function working properly

Highlighted
Occasional Contributor

I'm a noob with HUBL so I'm probably missing something obvious. I'm trying to split out a contact property into an array. I can get it to work when passing a string to the split(..) filter, but it fails when I put that string in the contact property.

 

My code is:

{% set string_to_split = contact.industry %}
string to split:
{{string_to_split}}<br />
{% set names = string_to_split|split(';', 9) %}
Names: {{names}}<br />
<ul>{% for name in names %}
<li>{{ name }}</li>{% endfor %}
</ul>

{% set string_to_split = "Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda" %}
string to split:
{{string_to_split}}<br />
{% set names = string_to_split|split(';', 9) %}
Names: {{names}}<br />
<ul>{% for name in names %}
<li>{{ name }}</li>{% endfor %}
</ul>

 

The first section doesn't work: the split function doesn't create multiple rows on the array, and just puts the whole string into one variable:

 

string to split: Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda
Names: [Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda]

  • Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda

 

But when i set the variable with a constant value, everything works as expected:

 

string to split: Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda
Names: [Stephen, David, Cait, Nancy, Mike, Joe, Niall, Tim, Amanda]

  • Stephen
  • David
  • Cait
  • Nancy
  • Mike
  • Joe
  • Niall
  • Tim
  • Amanda

 

I just can't see why the split function doesn't work the first time as the variable I'm passing is (on the face of it) the same both times. So why does the split function work on one, but not the other?

 

I'd really appreciate any help you can give


Thanks


Mike

 

 

 

Reply
0 Upvotes
22 Replies 22
Esteemed Advisor

hey @mikemaynard,

 

It might help if you told us what you are trying to accomplish. Are you wanting to list out all industries that are tied to your contacts?

 

I don't have much experience dealing with contacts or contact properties but I think that, while you can use contact.property to customize a page for the contact viewing it, you cannot use the contact variable to access your contacts database. For instance, I don't believe that you could output a list of all of the names of your contacts or other information onto a page. I did test this and it doesn't seam to work. 

 

Hubspot does have an api that includes the contacts api but their api's main purpose is for outside websites so it isn't easily integrateable into your portal and it also is not available by default. I believe there is an extra charge. 

 

Let me ask you this, does {{ contact.industry }} output anything to your page? If it works how I think you are wanting it to work then it would list all industries in you contacts list. if it works like I think it works then it will only output the industry tied to your contact profile, provided that you are a contact with the property "industry" filled out in your contact profile. 

- Jonathan Sumner
Occasional Contributor

Good point @Jsum

 

This is just a test, not what I am ultimately aiming to do. The ultimate goal is to be able to pass a large number of parameters from Salesforce to HubSpot - more parameters that we have fields available in Salesforce (probably around 100, but the exact number doesn't matter). These parameters are information about products that are related to something the contact has just bought online, so there are many, many combinations (ie. we have to pass them all as parameters, it's impractical to pass a code and then use workflows to do a lookup).

 

This is why I'm trying to split up a string of parameters. We can use a different separator (i.e. not ";"), and really any other approach that would work to split out a string into separate parameters held in an array.

 

So what I want to do is pass a large number of parameters and then split them up in the email design. I can do this with a constant string, but when I pass the same data via a contact property, the split filter doesn't work. I've literally cut and pasted the data from the string to the property, so I assume there is something going on when the data is either stored in the contact property or passed from a property to a variable, which means that split stops seeing ";" as ";". and therefore it fails to split the string. 

 

Thanks


Mike

 

 

Reply
0 Upvotes
Occasional Contributor

In response to the question:

 


  

Let me ask you this, does {{ contact.industry }} output anything to your page? If it works how I think you are wanting it to work then it would list all industries in you contacts list. if it works like I think it works then it will only output the industry tied to your contact profile, provided that you are a contact with the property "industry" filled out in your contact profile. 




 

If you look at the outputs, I'm outputing the variable {{string_to_split}} in both cases and they look exactly the same, but in one case split(..) works and in the other it doesn't do anything. I'm guessing there may be something hidden that I'm not seeing, but on the face of it the variable has EXACTLY the same contents, but the result of the split function is completely different.

Reply
0 Upvotes
Esteemed Advisor

@mikemaynard can you share the output?

- Jonathan Sumner
Reply
0 Upvotes
Occasional Contributor

When using {% set string_to_split = contact.industry %}

 

string to split: Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda
Names: [Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda]

  • Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda

 

When using {% set string_to_split = "Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda" %}

 

string to split: Stephen; David; Cait; Nancy; Mike; Joe; Niall; Tim; Amanda
Names: [Stephen, David, Cait, Nancy, Mike, Joe, Niall, Tim, Amanda]

  • Stephen
  • David
  • Cait
  • Nancy
  • Mike
  • Joe
  • Niall
  • Tim
  • Amanda

 

As you can see, {{string_to_split}} looks to be identical in both cases, but when I create {{names}} using split(...), the first time it's just a string and isn't split, whereas the second time (setting the text as a constant) I've created an array by splitting the string with the ";"s. 

 

I did cut and paste the string into contact.industry for this contact that I'm testing with, so it should be the same. And the output looks the same. But presumably there is some difference that i just can't see!

 

Thanks for your help.

Reply
0 Upvotes
Esteemed Advisor

@mikemaynard, that is confusing me. Why does the contact.industry variable print out a list of names?

- Jonathan Sumner
Reply
0 Upvotes
Occasional Contributor

Hi @Jsum you are reading too much into the property and the values. This is just a test. I will create a new custom field, and the contents will be completely different once I get this to work. I just used a convenient string (the one used in example HS code) and convenient property (something I display for all contacts so it's easy to change) for the test. The name and content are irrelevant

Reply
0 Upvotes
Esteemed Advisor

@mikemaynard,

 

No I don't believe that I am because I as attempted to explain to you several times, you probably won't be able to use the contact variable the way that you are attempting to use it. And besides, your code example above clearly states that you ARE using the contact.industry variable and it is printing out a list of names. Unless you have assigned a bunch of names to the industry fields of your contacts profiles, or you overwrote the variable with the names and didn't show this, then your output makes absolutely no sense. There is no other way that you could be retrieving a list of names from that variable. 

 

The reason I am so concerned about your output is that you seam to think that your issue is with the filter you are using while I think your issue is related to the above. Without understanding what you are trying to do, and what you have already tried, I can't very well help you find a solution. 

 

All I can say is that if it is an array you output the contents with a for loop and so filtering it is not necessary. If it's a string then splting will work. 

<li>{{ array.property[0] }}</li>
<li>{{ array.property[1] }}</li>
<li>{{ array.property[2] }}</li>

or

{% for item in array.property %}
    <li>{{ item }}</li>
{% endfor %}
- Jonathan Sumner
Reply
0 Upvotes
Occasional Contributor

@Jsum I'm not being clear, and so I'm really sorry.

 

Let's change the string to a list of industries: 

{% set string_to_split = "Media; Marketing; Advertising; Sales; Digital; Web; PR; CPC; SEO" %}

 

I want to display the list of industries as a bulleted list in the email. If I assign string_to_split as above then it displays as:

  • Media
  • Marketing
  • Advertising
  • Sales
  • Digital
  • Web
  • PR
  • CPC
  • SEO

If I cut and paste the same string into contact.industry,  and assign the string like this:

{% set string_to_split = contact.industry %}

then the split(...) filter does not work, and the industries are all on the same bullet:

  • Media; Marketing; Advertising; Sales; Digital; Web; PR; CPC; SEO

Yet it appears that the variable string_to_split is assigned exactly the same value. 

 

Does this make more sense to you now?

 

Thanks


Mike

Reply
0 Upvotes
Esteemed Advisor

@mikemaynard, I still don't understand where the contact.industry is coming from. If you are constructing it yourself or if it is an actual system variable outputting actual system information, but here is the deal:

 

The reason split is not working on your first example is because it is an ARRAY, not a string. I just tested it and this is 100% a fact. You cannot, nor do you need to, use the split filter on an array. You can use it on an item of an array, but not on the array itself. 

 

What you are attempting to do with the split filter is fake an array out of a string. This works in your second example because it is a string but is NOT necessary in your first example because it is already a 100% real array. You don't need to split it. 

 

I took the list of industries you gave me and I created an array:

{% set string_to_split = ["Media", "Marketing", "Advertising", "Sales", "Digital", "Web", "PR", "CPC", "SEO"] %}

I then loop through the array:

 <ul>
{% for industry in string_to_split %}
         <li>{{ industry }}</li>
{% endfor %}
</ul>

and the output is this:

<ul>
          <li>Media</li>
          <li>Marketing</li>
          <li>Advertising</li>
          <li>Sales</li>
          <li>Digital</li>
          <li>Web</li>
          <li>PR</li>
          <li>CPC</li>
          <li>SEO</li>
 </ul>

while this:

{% set names = string_to_split|split(';', 9) %}
<ul>
{% for name in names %}
         <li>{{ name }}</li>
 {% endfor %}
  </ul>

produced this:

<ul>
         <li>[Media, Marketing, Advertising, Sales, Digital, Web, PR, CPC, SEO]</li>
</ul>

 If you are playing with data coming from the Hubspot system, chances are the data is set up to be an array, not a string, while the values of the array keys could be strings, ints, etc. This being the case, if content.industry is in fact hubspot system data, just treat it as a array, not a string. 

 

if contact.industry is your own creation, make it an array. there is no point in going through the trouble of filtering a string to act like an array when you can just use an array from the start. I have created very in depth and complicated dict arrays in hubspot that work wonderfully in terms of output so the sky is the limit if you treat your data right.

- Jonathan Sumner
Reply
0 Upvotes
HubSpot Employee

Just to share my test on my own account. I set up this code on a landing page template in a HubL module. Converted the existing industry property to multi-checkbox. Went into a test contact and selected the options I wanted. Then when I viewed the page as a specific contact I noticed the string was not separated by (Smiley Wink but instead (,)

Changed the split to look for a comma instead of the semicolon and it worked.
Screen Shot 2017-06-23 at 11.15.08 AM.png

Reply
0 Upvotes
Occasional Contributor

Thanks @EricSalvi. I should have tested a LP earlier, but never thought the results would be different.

 

I've been working on an email. So I cut and pasted my code into a landing page. IT WORKED. (FWIW the separator makes no difference, my original code with the semicolon separator works fine on a landing page too).

 

So: GOOD NEWS - my code is OK

BAD NEWS: there appears to be a bug when using HubL to create emails. Is there a way to get this fixed asap?

Reply
0 Upvotes
New Contributor

I just ran into this issue myself, spending way too much time trying to figure out why split(..) would just silently fail and always return a string.  For anyone else stumbling across this, I then found this bug report saying it is not a bug, but that the feature does not exist for emails:  https://community.hubspot.com/t5/COS-Design-Support/Split-filter-bug-report-in-Email-Module/m-p/2031...  

 

It seems like the ability to create any kind of custom dynamic emails based on customer properties is essentially impossible with HubSpot without this functionality, unless you're just using a simple string.

 

@mikemaynard Where you ever able to find a work around?  I'm trying to do the same thing as you... work with a simple array of data from a customer property (which btw you explained very clearly in your original post) 

Reply
0 Upvotes
Occasional Contributor

Hi @ryan3

We're looking at using Scribe (https://www.scribesoft.com/). It is more than capable of doing what we need, although it is reletively expensive if this is all we use it for. I've heard some good things about the team, and apparently support is very good.

Mike

 

 

Esteemed Contributor | Diamond Partner

Holy cow I am not crazy - I have been troubleshooting the exact same thing @mikemaynard.

 

Here is the use case.

 

We have a library of resources on a site. A user can fill out a form to access a resource. The pages we have the resources living on are built on WordPress and have some nifty dynamic php behind the scene that outputs 3 related resources to the current resource on the page.

 

The marketing team wants to output these resources inside the emails sent via HubSpot's workflows. The way I was envisioning this working would be to send a blob of CSV data through a hidden text area (a custom contact property) on the form submission and then parse it using a custom HubL email module and loop through it. 

 

There are 2 really screwy things about HubL:

 

  1. You can't parse or typecast a variable into any other type than a string UNLESS you manually parse the string using |split (no filters exist to my knowledge)

  2. That HubSpot magically removes all filter capabilities for email.

 

I was so pumped that I thought I could get this to work... HubSpot - please allow the use of some filters in email... This is stopping us from making our drip campaigns truely "automated" with how our CMS organizes content.

Occasional Contributor

This is unfortunate,

we have a very similar use case @derekcavaliero did you come up with any other ideas to near your goal?

 

The wound of learning this is not possible with Hubl in an email is still fresh for me!

Reply
0 Upvotes
Occasional Contributor

There's not much you can really do to overcome this. The two possible ways of having more dynamic content are either adding content to a contact property or using smart lists to switch content in and out of an email. Either way, you'll struggle to use complex rules or individually personalise content.

 

The only other way I can think is to implement the HubL logic in something like Scribe Online. It's a great product that would be able to apply complex rules to create content (which would be HTML) in contact properties. But it's going to cost you around $3-400 per month, I believe.

Reply
0 Upvotes
Occasional Contributor

Thanks @mikemaynard,

Agreed, using the built in personalization tags along with a custom multi-check contact property is where we have ended up. It is not ideal but a happy medium for us right now.  

 

As you have mentioned Scribe definitely would meet our needs, but we would need to ramp up our requirements to justify the cost. Thanks for the link though I'll take a deeper look at their solution.

Reply
0 Upvotes
Esteemed Advisor

If your resource's would using Hubspots blog system you could simply use a blogs by topic function, passing the related topic to the topic to filter by part of the function.  I've done similar before.

- Jonathan Sumner
Reply
0 Upvotes
Occasional Contributor

@Jsum - replying separately to the comment about arrays:

 

In both cases I am creating a string called string_to_split and then creating an array using split(...). When I assign the string using "...." it works perfectly. When i assign the string using the contact property it does not. In both cases I have *definitely* assigned a string (checked using pprint) and in both cases the string *definitely* looks the same (again checked using pprint as well as displaying the variable). But in one case the split(...) produces an array and in the other it does not. If I could produce an array when using the contact property I completely agree that displaying the elements is trivial.


Thanks

 

Mike

Reply
0 Upvotes
HubSpot Employee

@mikemaynard
Maybe before the |split filter, I have had success in the past with others to squeeze in the |string filter first. Could look like this

string_to_split|string|split(';', 9)

Maybe that will work?
@Jsum I can see he already showed the example output in the initial question.

Reply
0 Upvotes
Occasional Contributor

Thanks for helping @EricSalvi. Unfortunately it didn't work.

 

I tried: 

{% set names = string_to_split|string|split(';', 9) %}

and unfortunately the behaviour is still exactly the same. it splits string_to_split when it's assigned with a constant value, but not with the contact.industry property.

 

Reply
0 Upvotes