Current position in format as text

Does anyone have a good approach for formatting a list with a reference to the current position of the list?

This is possible with a workaround with list of numbers etc, but curious if there’s a simpler way.

E.g. if you wanted to format a list of text as:

{“id”: 1",“content”: “text”},{“id”: 2",“content”: “text”},{“id”: 3",“content”: “text”}

How would you get the id?

Thanks

If your list of text contain unique elements and no element contains the other one as a substring, I have a solution.

From this list of artist names, I could get this JSON array:

The idea is:

  • merge the names with a comma at the beginning instead of a delimiter,
  • then split by the artist name,
  • get the first part of the split,
  • split by comma,
  • count the comma,
  • subtract 1 from the count.

This will give your the index.

Now, how it is done:
I have an Artist data type with Name field (text). I put this formula to a textbox.
image

Format as text to combine the names as json:

See the id field, it is the calculation I explained above. An important part is the format as text. See there is no delimiter, and comma is at the beginning. This is to get the correct index numbers. I have tested some more configurations. This one works.
image

Then, you can see the split by (This Text), get the first item, split by (,), count-1 (which are all explained above).

Maybe this can give some people inspiration and we can find a generic version of it without the limitation mentioned in the first sentence.

Thanks @hergin! Creative solution however lot’s of searches and might break with duplicate values. Probably simpler on the frontend to format a list of numbers as text referencing the original list within.

E.g. list of numbers:format as text — > id:this number, text: text(s)item#this number

Still don’t know what I can do on the backend though…

Yes. I wouldn’t use it in the production. Just a brain teaser :slight_smile:

1 Like