Best answer

Brackets vs Underscores in "Shortcodes"

  • 23 December 2019
  • 5 replies
  • 400 views

Userlevel 7
Badge +9

I'm not sure what the proper term is, but when you copy a value from a field in a Zap and paste it in a text editor it looks something like {{44202530__Item}} I'm calling those short codes for this conversation... please correct me if there is a proper term for it.

But recently when working with Line Items I found these two give different results, one works when there's only one line, and another works when there are multiple lines.

  • {{44202530__output[]Item 4}}
  • {{44202530__output__Item 4}}

So what is the difference as to why sometimes it uses square brackets([]) versus underscores(__) ?


icon

Best answer by TimS 2 January 2020, 02:29

Hi @PaulKortman, you're definitely not crazy! I've come across this behaviour, too. 

When looking at the value mappings (that you're calling shortcodes here), both double underscores __ and square brackets [] denote nested values. Names after __ are nested single values and names after [] are nested arrays (what typically we call line items).

As a general rule, what we'd want to see is that any time a nested value could be an array, it should be presented as such with [], even if it only has one item. The problem is that I've seen some app integrations that when only receiving a single item for an array don't wrap that single item in an array, so we end up with __ instead. 

If we're seeing an array value that doesn't look like an array in Zapier when there is only 1 item, we should be creating a bug report for that issue. If the app giving this data is public, please let us know by submitting a support ticket so that we can do that for you.

In the meantime, the solution would be to map both possibilities into the field you're sending the value to in the Zap. If the mapped value is usually {{123456__value_name[]Item}}, then you'd want to also map {{123456__value_name__Item}} into the same field so that whichever one comes through will be sent to that Step in the Zap.


View original

This topic has been closed for comments

5 replies

Userlevel 7
Badge +10

I know [] are used with arrays - could be something around that?


Userlevel 7
Badge +8

@PaulKortman it sounds like @AndrewJDavison_Luhhu is likely correct about this and the brackets are for those that contain multiple values (arrays). Were you able to confirm this on your end?


Userlevel 7
Badge +9

I think it's right, but I don't get it, I split a block of text into fields (based on the [:newline:]) and then I have 7 Items/fields. But before that step I split the block(s) of text into line items, based on a keyword. So here's a visual:

0:

  • Field 1
  • Field 2
  • Field 3
  • Field 4
  • Field 5
  • Field 6
  • Field 7

1:

  • Field 1
  • Field 2
  • Field 3
  • Field 4
  • Field 5
  • Field 6
  • Field 7

And in this case the square brackets [] works, {{44202530__output[]Item 4}} and I get line items (comma separated) for Field 4. Where as {{44202530__output__Item 4}} gives me nothing.


If however I run a different data set through the zap that only has one paragraph (not two like the example above) In my head I should get the following:

0:

  • Field 1
  • Field 2
  • Field 3
  • Field 4
  • Field 5
  • Field 6
  • Field 7

But the square brackets don't work in this case, and I have to use {{44202530__output__Item 4}} to get the value of Field 4. Perhaps the data actually is not line items because there is only 1 result or only 1 line, so perhaps the data is actually:

  • Field 1
  • Field 2
  • Field 3
  • Field 4
  • Field 5
  • Field 6
  • Field 7


So right now I'm using both in my Zap, for a field where I need the value(s) from Field 4 I use:

{{44202530__output[]Item 4}} {{44202530__output__Item 4}}

Which seems problematic, sometimes there is an extra space before, sometimes after, in this specific Zap it doesn't matter, but it seems crazy to me that I have to specify both to account for when it has one one "line" versus when it has multiple lines.

Am I crazy? Has someone else seen this?


Userlevel 5
Badge +2

Hi @PaulKortman, you're definitely not crazy! I've come across this behaviour, too. 

When looking at the value mappings (that you're calling shortcodes here), both double underscores __ and square brackets [] denote nested values. Names after __ are nested single values and names after [] are nested arrays (what typically we call line items).

As a general rule, what we'd want to see is that any time a nested value could be an array, it should be presented as such with [], even if it only has one item. The problem is that I've seen some app integrations that when only receiving a single item for an array don't wrap that single item in an array, so we end up with __ instead. 

If we're seeing an array value that doesn't look like an array in Zapier when there is only 1 item, we should be creating a bug report for that issue. If the app giving this data is public, please let us know by submitting a support ticket so that we can do that for you.

In the meantime, the solution would be to map both possibilities into the field you're sending the value to in the Zap. If the mapped value is usually {{123456__value_name[]Item}}, then you'd want to also map {{123456__value_name__Item}} into the same field so that whichever one comes through will be sent to that Step in the Zap.


Userlevel 7
Badge +9

@TimS Thank you so much for the response. I already had done the work around you suggested but I thought perhaps this was poor form on my part or that I was doing something wrong.

In this case it is a public app (webflow) and I will submit a support request to create a bug report. But it's good to know I'm not crazy, that with one sample data the brackets work and with another sample data the brackets didn't work. It was a bit of a stroke of luck to me that I even caught this before it went into production. But now that I know to look for this and that it's not impossible to have these situations it'll make it easier to spot in the future.