Best answer

Text in Formatter Extract Is Returning Every Occurrence Instead of Just 1

  • 24 June 2022
  • 8 replies
  • 238 views

Userlevel 1

Can anybody help figure out why this is not simply returning the ID at the end of this sequence? 

 

I’m trying to just extract the letters/numbers after the comma but it seems to grab all of the occurrences even with Match All set to No.  There is a set of 4 values all comma separated, but I’m only trying to grab the last one.

 

Setup:

 

Current Output:

 

 

icon

Best answer by Troy Tessalone 24 June 2022, 16:37

View original

8 replies

Userlevel 7
Badge +14

Hi @JutstinD 

Good question.

Instead try this: Formatter > Text > Split

Userlevel 1

Hi @Troy Tessalone  thanks for the suggestion.  I’m getting the same issue, it returns all 4 matches instead of just the last even though it’s set to last.  

It is inside of a loop so maybe this is a bug with the loop function causing it?

I managed to find a workaround by using this python code snippet and Code By Zapier.  Not sure why these other methods are returning every match even with the qualifiers.

 

fields = input['custom_fields']

id = fields[fields.rfind(',')+1:]

output = {'id':id}

Userlevel 7
Badge +14

@JutstinD 

It may have to do with the format of the data.

  1. Array with line items separated by commas
  2. String with values separated by commas.
Userlevel 1

Good point @Troy Tessalone .  It seems odd b/c it is splitting everything in both instances the way it should, just the return seems to be incorrect. 

Userlevel 7
Badge +14

@JutstinD 

We’d need to see screenshots with how you have each Formatter action configured in order to evaluate and advise.

 

FYI: There are also these Formatter options…

Formatter > Utilities > Text to Line Item

Formatter > Utilities > Line Item to Text

Userlevel 1

 

Here’s some screenshots of the split attempt.  Maybe I’m missing something but this is what it’s giving me and when I try to use the output variable it contains all 4 pieces.

Userlevel 7
Badge +14

@JutstinD 

FYI: When using a Code step, all input parameters are treated as strings. (e.g. array gets converted to a string, number gets converted to a string, etc.)

 

Here’s what’s likely happening with the Formatter > Text > Split as you had it configured…

The input value is an array, so the Formatter > Text > Split step is merely returning the array line items, since the input value is not a text string, thus the step is not actually finding any commas to split by due to the nature of the data (array vs text).

 

Example when I test with a string input separated by commas

 

 

Try this instead with the Formatter: (see screenshot note)

  1. Formatter > Utilities > Line Items to Text (delimit with comma)

 

Example

 

 

Userlevel 1

There it is, @Troy Tessalone  Thank you for all of the help on this!  I didn’t understand why it was returning me a string of all of my custom fields to begin with, so it makes a lot more sense that it was actually an array.

 

Thanks again, that works perfectly!

Reply