Pull up a variable at the top of a list of variables

Hello Makers, I got a list of fruits in a Google Sheets :

  • Apple
  • Banana
  • Orange
  • Mango
  • Strawberry
  • Blueberry
  • Pineapple
  • Watermelon

If I got one of them as an input, how to put it at the top of the list?

For example, I got Strawberry from a Webhook trigger, then I use the “Get range Values” Google Sheets module. Finally, I want to reorder the list and display it in an email for example, like this :

  • Strawberry
  • Apple
  • Banana
  • Orange
  • Mango
  • Blueberry
  • Pineapple
  • Watermelon

Hi @Garry_V, Does this work for you ?

We’ll use getRange from sheets and aggregate all fruits in one big text separated with a comma, but ignore the topFruit (strawberry). We’ll then split this list back to a list (filtered array), and add strawberry as first element of the list. I use here merge() with one-element array of Strawberry and filtered array without strawberry.

Here’s the json : topfruit.json (14.1 KB)

Please mention me if you have further questions.

Edit : found an improvement - the last step of integrating topfruit into the array can be done in text aggregator module itself. we add if(bundleposition=1;topfruit,;emptystring). This will effectively add topfruit on top of the first element.

Splitting this back with , separator would get you a proper array of elements. The empty element shouldn’t be a problem and can be removed from the array.

1 Like

One way to do this would be to remove item from the array, then remake the array with join+split.

blueprint (25).json (5.1 KB)

Hi @XenoMax, The problem is that the range from Sheets would be a list of bundles and the only method I’ve found to convert it to an array is text aggregator - and then split it.

@Garry_V, in text aggregator just add : if(boolean=true; PRO;emptystring)