Question

Looping: Splitting a string containing commas


Userlevel 1
Badge

Hi all,

I’m building a database-update Zap. I want to loop a set of record-creation steps across an incoming array, and ultimately create a new record for each element.  I have tried both Formatter and Looping, and run into the same problem.

The problem is getting airtable to correctly recognize/split/delimit the text string in the array, because the strings are delimited by commas, but also contain commas.

Sample data:

ID: 4824720,4824729,4824724,4824725

Name: MODULAR FUSELAGE, MAIN BODY V4.SLDPRT,FTLK.4._production_SLDPRT.SLDPRT,ADAPTER, KRAKEN V2.SLDPRT,ADAPTER, LIFT V5.SLDPRT

 

Zapier splits up ID into a correctly sized array fine. But it splits Name at every comma, resulting in a pair of mis-aligned arrays (because ID gets correctly broken into 4 elements but Name gets broken into 7).

 

This seems to be a known issue, but without one single solution, and a lot of how-tos predate Looping. Is there a straightforward way to do this? Thanks in advance


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

20 replies

Userlevel 7
Badge +14

Hi @Tha_Lichen_Enjoyer 

Good question.

One workaround to try is to first use a Formatter step, followed by a Looping step.

Formatter > Utilities > Line Items to Text (set Separator to ||)

Looping - Create Loop from Text (split by ||)

Userlevel 1
Badge

Hi Troy, Thank you for your reply!

I have actually tried this, and get a problem where Formatter duplicates the entire input. This happens whether I use text-to-line item or line-item-to-text.

Below I use the simpler ID data as a test, but the same thing happens if I try to use Name

I also tried using Formatter>Replace upstream of the loop. It succesfully replaces the non-delimiting commas (because they are always followed by a space), but I get the same duplicated-block output.

 

Line-item-to-text interprets the input block as identical line items, and duplicates the entire input into the text multiple times:

item_1: 4824720,4824729,4824724,4824725

item_2: 4824720,4824729,4824724,4824725

item_3: 4824720,4824729,4824724,4824725

text: 4824720,4824729,4824724,4824725||4824720,4824729,4824724,4824725||4824720,4824729,4824724,4824725||4824720,4824729,4824724,4824725||

Text-to-Line-Item breaks the text up correctly, but breaks it into multiple duplicate arrays.

1

    1: 4824720

    2: 4824729

    3: 4824724

    4: 4824725

2

    1: 4824720

    2: 4824729

    3: 4824724

    4: 4824725

3

    1: 4824720

    2: 4824729

    3: 4824724

    4: 4824725

 

Userlevel 7
Badge +14

@Tha_Lichen_Enjoyer 

Please post detailed screenshots with how your Zap steps are configured to give us more context, thanks.

Userlevel 7
Badge +14

@Tha_Lichen_Enjoyer 

Try this…

Step: Formatter (do for each array - ID and Name)

Example for Name (where there could be commas in the line item value)

 

 

Userlevel 1
Badge

Sure. Here is the Formatter step, which is the first step after the trigger (I’ve isolated it for simplicity). This is done using data, but the same thing happens with name.

 

 

 

Userlevel 1
Badge

(Deleted accidental duplicate comment).

 

Userlevel 1
Badge

(Deleted accidental duplicate comment)

Userlevel 7
Badge +14

@Tha_Lichen_Enjoyer 

Ok, that means the data is not an array of line items, rather it’s a string of text.

Can you provide a screenshot of the data OUT from step 1?

Userlevel 1
Badge

Right. Thats why I also tried text-to-line-items

Userlevel 7
Badge +14

@Tha_Lichen_Enjoyer 

Can you provide a screenshot of the data OUT from step 1?

Userlevel 1
Badge

By Step 1, do you mean my trigger step, step one in the whole Zap?

Userlevel 7
Badge +14

@Tha_Lichen_Enjoyer 

One approach might be like this for the Name data.

Action: Formatter > Text > Replace (replace all instances of a comma followed by a space with ^^ )

Action: Formatter > Text > Replace (replace all commas with ||)

Action: Formatter > Text > Replace (replace all instances of ^^ followed by a comma with a space)

 

NOTE: You can do this all in 1 Code step.

 

Userlevel 7
Badge +14

@Tha_Lichen_Enjoyer 

By Step 1, do you mean my trigger step, step one in the whole Zap?

Step 1 is the trigger step of the Zap.

Userlevel 1
Badge

@Tha_Lichen_Enjoyer

One approach might be like this for the Name data.

Action: Formatter > Text > Replace (replace all instances of a comma followed by a space with ^^ )

 

 

I also tried using Formatter>Replace upstream of the loop. It succesfully replaces the non-delimiting commas (because they are always followed by a space), but I get the same duplicated-block output.


I will post my step one out data in a sec. It’s unwieldy.

Userlevel 1
Badge

The test output data is way too big to entirely screenshot, but here’s the top part and one instance of the name data (second screenshot, ‘paert_name’ field)

 

 

Userlevel 7
Badge +14

@Tha_Lichen_Enjoyer 

Try this approach…

One approach might be like this for the Name data.

Action: Formatter > Text > Replace (replace all instances of a comma followed by a space with ^^ )

Action: Formatter > Text > Replace (replace all commas with ||)

Action: Formatter > Text > Replace (replace all instances of ^^ followed by a comma with a space)

 

NOTE: You can do this all in 1 Code step.

Userlevel 1
Badge

Sorry, I tried to indicate earlier that I have already tried that and it runs into the same block-duplication problem. You can see the results below. It successfully finds and replaces the non-delimiting commas, but still outputs an array rather than single text string.

One complete name entry is highlighted. You can see it repeats in every block.

 

 

Userlevel 7
Badge +14

@Tha_Lichen_Enjoyer

The most robust way to handle the data would be in 1 Code step.

If you need help consider hiring a Certified Zapier Expert: https://zapier.com/experts/automation-ace

Userlevel 1
Badge

 @Troy Tessalone this does not seem like an especially complicated problem - it’s pretty clearly a data classificiation/recognition issue - it just doesn’t conform to either of the suggestions you offered. I have to be frank that your approach is frustrating: Even though my original messages clearly indicated I had already tried the approaches you suggested, you requested me to extensively verify this with screenshots - and then just bumped me to the paid expert service when it became clear I had already exhausted the steps indicated in your stock response, rather than actually exploring the problem with me at all.


I appreciate your time and effort, but if you’re not willing to engage beyond canned/stock responses, even after someone takes the time to extensively screenshot/document in response to your questions, please consider leaving the question to someone else.

 

Userlevel 7
Badge +14

@Tha_Lichen_Enjoyer

Handling line items in Zaps can be tricky. (as you’ve experienced)

 

The Formatter options can’t handle every use case.

 

We needed to be able to see screenshots of how your Zap steps are configured and the format of the data to have proper context, which was not provided in your original post, hence the need for additional follow ups. (telling us is different than showing us)

 

I would solve this with 1 Code step using JavaScript, but that’s an advanced approach.

There’s a limit to how much free feedback I’m willing to provide especially when it comes to Code step, since I’ve previously invested the time and effort into solving for these type of use cases.

Hiring a Zapier Experts is an option to explore when you need help configuring Zaps.

 

Here’s some context about my contributions to the Zapier Community: