[Solved] Last item -1 (penultimate element)

Hi,

what is the best way to get the penultimate value of a list?

I was guessing to use a “item #:count-1” or “:last-item-1” but non of them is available.

Best

You could try :sorted (then reverse your sort order) and select item #:2. Or try the method described here: Penultimate date

1 Like

mmmh, it’s an interesting solution but:

  1. :sorted is sorting by what? only alphabetical order?
  2. where Im trying to get the penultimate value is a field of a record in the database, which is a list of strings; i cannot order them alphabetically, it has just to take the penultimate element of that field(list)

thanks for your suggestion

I see. I don’t have Bubble in front of me right now to try this but if you’re using a repeating group, what about using the index number? So RG is a list of texts and you look for the item with index number = count of entries - 1. Unless of course this is what you mentioned that you had already tried without success.

Your suggestion is right but the only thing missing is the -1 at then, that Bubble does not accept. Maybe there is another workaround that I don’t know.

A bit of a hack but it works - see here

I’m sure there’s a clever regex way to this more elegantly though.

1 Like

You’re an absolute genius. This workaround is simply diabolic :smile:

I just hope this is gonna always work, I say this because of the random order of execution of workflow actions in Bubble. I think @emmanuel should add the support for this kind of concatenation of rules when a user wants to apply a -1 to :count result.

Thanks again @louisadekoya for your help.

1 Like

You’re welcome. I don’t see why this wouldn’t always work. The only time I’ve seen any apparent weirdness in workflow order is when an external API call takes a long time to complete and other steps run in the meantime. By the way, the group is not really necessary in my solution, you should be able to add the custom state to the text itself.

This topic was automatically closed after 70 days. New replies are no longer allowed.