Any suggestions for how to automatically sort the contents of an array so that the elements appear in alphabetical (or alphanumerical) order?
I’d be super curious if anyone has built this using the trigger editor in Tulip. This suggestion sounds like a perfect use for custom widgets + ChatGPT.
Has a solution or workaround been found for sorting the contents of an array? (alphabetically or alphanumerically)
Hi Niklas,
Are you able to access an SQL database + SQL Connector? If so, you can write a simple SQL Query to take in an array joined into a string, and then output an array after sorting.
In the code below, I am also getting rid of duplicate entries.
I had the same challenge and resorted to triggers performing sorting by swapping elements in the array (which is silly). If we are to stick to standard functions and not program widgets to perform sorting maybe it isn’t such a big deal for the product team to add a “Sort array” action to the list of array functions. What is the Tulip product opinion on this?
Hi, is there an update regarding this topic?
Hi @OliverGnepper and others!
We actually talked about this in Office Hours on June 13th with @jmlowden and have a workaround option. Similar to what @dsun proposed, if you are pulling data into your array from a Tulip Table, you can use the query to sort alphabetically, and then when you are taking aggregation and pulling into an array, the array will be populated alphabetically.
So basically, if you can get your data sorted ahead of time, you can pull it into your array alphabetically.
However, I know it would be easiest if there was an array function that allowed you to do this natively, so I will see if this is something on the Product Team’s radar as well!
Hi @Beth,
thanks for providing the updated information. The described workaround covers only the use case where the data is consumed from a third party system. I don’t see how this workaround covers use cases where the data comes from user inputs.
Hi @OliverGnepper,
The point about sorting arrays is definitely heard and understood.
Sincerely,
Jake
You could pass the user input data into a “scratch pad” table, linked by a common session or step or event ID column value, and then use the query/sort/aggregation to get the unique values in your preferrred sort order, then pass them back to the app.
Thanks for your advise. I already hat this option in mind, but since multiple stations might use this function simultaneously several questions (e.g. information separation, information access, failure management, cleanup, …) arise which would be covered best by an in-app solution.
You could resolve that concern by tagging the table records with a unique “session ID” that is generated when the app is started - for ours we make this a string including the app name/version, datetime, user username, etc. We use that routinely for grouping table data generated within a single app session, to allow for querying those records as a group (i.e. to review/correct data generated within the session).
Also, if there are records created across multiple apps/sessions but related to a common “event” (or “batch”), you can have another “event ID” tag to group those in queries.
This suggestions solely covers the information separation topic. The stored information is still accessible for unauthorized persons, the in app failure management doesn’t work and a separate cleanup process is also necessary.
You might call me narrow minded, but I tend to omit a function if there is only a half-baked tinkered solution.
I am actually using a custom widget to eliminate duplicates and sort a list.
let processedList;
getValue("Text_List_Input", (internalVariable) => {
processedList = [...new Set(internalVariable)].sort();
setValue("Text_List_Input", processedList);
fireEvent("Text_List_Processed");
});
It will change the input itself immediately
Feel free to only change it to only sort the list.
But keep in Mind: This way of sorting will separate all capital letters… e.g.:
- Apple
- Bus
- Car
- angle
- busy
and not:
- angle
- Apple
- Bus
- busy
- Car
The Event is optional and not relevant for the widget to work.
If “The point about sorting arrays is definitely heard and understood.” wondering why “Sort” function in “Arrays” is still not available? What product feature selection process for the next build/release/roadmap is stopping from giving this universal feature… instead of recommendations to go around looking for alternatives or building custom widgets!
Hi @bharatreddyv , pleasure to meet you on the Community forum
I’m a new Product Manager at Tulip, taking over the team responsible for logic - including triggers, arrays, automations, etc.
Acknowledge your really valid feedback here about the difficulty of interacting with arrays today. Agree that some of the ideas mentioned here are a bit of a workaround. I’d personally love to improve the experience of working with arrays, and would be happy to share our thought process for identifying and prioritizing roadmap items.
quick tl;dr - the next item we’re working on in the area of “logic” is a step into logic reusability, creating a new feature called Functions, which we’re hoping to release in the next few months, and then iterate on. We’re also the team responsible for Automations and are planning a few improvements there around version & run history storage and publishing.
Would you be open to a quick call to introduce myself, chat through any questions you may have around this, and also the separate thread on global variables? If so, I’ll reach out over email with some times.
Appreciate your presence and input!
- Olga