Table Aggregation Unique values trigger logic

A quick search didn’t help me find what I’m looking for…

I would like to be able to determine if a table aggregation of unique values returns an array length > 1.

Basically, if only one value is returned, there’s no need to prompt the operator to select a value so I would prefer to skip prompting the operator for a selection when there is only one choice.

Is this currently possible in LTS 10?

I think I found a way but it’s not exactly clean. You can’t directly test for array length in trigger logic.

What I had to do was create a separate trigger to store the array length to a variable and then check if the length was > 1 in a subsequent trigger.

Hey Richard, the approach you took is what I would do as well - but let me see if the team has any other suggestions!

@Richard-SNN A Tulipian suggested you could also try doing an aggregation that does a Count on the same Query and same filters as the use case returning Unique Values.

Then you don’t have to do the separate trigger to store array length (because you will get that with the count), and just need the trigger logic to check to see if it is greater than 1

That works! The logic would be a little cleaner that way.

Thanks!

1 Like

Awesome - one other tidbit I just got about this - Arrays are re-built every time they’re referenced (like it would be if we are doing the array get length trigger), so doing the count on the same query is the more efficient way for the software to run as well!

Look likes I spoke too soon, at least for my particular use case.

Because the table represents all production events, there will always be more than one row returned (after the 2 part is made) even if only one asset is used for production, so I can’t count records.

In this particular use case my current method will only return a few rows though so I don’t think performance will be an issue.

Whats missing is the length of array function in the expression editor.
The get from index function is also missing.

However, would the “Get length” trigger be an issue? This should work as intended?

@Beth
Richard wants to check on an Aggegation, not on a query. The Query could have multiple results, where the unique Aggregation deliveres only one.
There is no “count unique” aggregation.
Or did I get the idea wrong?

About the performance, I’m not sure. The Aggregation should always be updated, when touched or referenced?!
It behaves different than regular arrays (e.g. you can’t manipulate them).

Richard and Thorsten, in revisiting this use case, I agree with the method used by Richard in his second post. In neither LTS10 nor later versions do I see a cleaner way to get a Length of a Unique Values aggregation. The Count would just return the Count of the records on the Query itself, not the Count of the Unique Values.

My apologies to Beth for providing wrong guidance earlier.

1 Like

The original question was if a aggregation had a length greater than 1.
I actually just add +“” to convert to a string and then length of a string is easy.

In my latest use of this I present the user with a list of tasks (remaining areas to clean) and if they mark all of them I need to show that they will also provide the final signature for all areas.
In this case I compare the areas to clean and the array of choices are the ones not yet signed off. It might be on the fringe of your question but converting to string is another way of working with arrays and aggregation results…

Picture of choice list:

Picture of trigger that performs compare:

I hope this makes sense to others having same challenge… :slight_smile:

1 Like

Great input @ASharp-J

I was thinking about a similar solution but was hesitating, because it is dependent to the length of the string (and you might have different values with different (unknown) length…

But you pushed me rethinking it, and I came up with his solution (I actually used a similar technique before :smiley: )

@Richard-SNN
What do you think about searching for a comma? (only make sure, to have no comma in the values :wink: )


Update:
using TOTEXT(…) is more secure, because you can search for "," then (a simple comma in the value is no longer an issue)

Context for the update:
TOTEXT(@Table Aggregation.Aggr_Test) output is like so:

["j4gmt7PjnBu23s5R7","cjAMazfQowczQNMEsmx589fTgtoSu2RQjk"]

while @Table Aggregation.Aggr_Test + '' outputs something like this:

j4gmt7PjnBu23s5R7,cjAMazfQowczQNMEsmx589fTgtoSu2RQjk
1 Like

I think both would work in my case, with the downside that it does hurt readability by those that follow behind us.

My method, while much less efficient, is very easy to understand what I’m trying to do, but I will consider refactoring if performance becomes an issue.

Interesting discussion though!

1 Like

@thorsten.langner and @ASharp-J thanks for your input and for helping determine multiple aways to approach the problem!

awesome discussion that will be helpful for many other users down in the future as well :slight_smile:

I think Richards comment on readability is fair and I agree that some expressions are not so easily interpreted. I have at least implemented some fairly complex time calculations in single expressions that required some explanation (calculating expiration dates as end of month x months into the future / ensuring a new expiry date is placed correctly on same weekday arbitrary weeks into the future).
In those cases explanations might need to be anchored outside the system. @Beth, do you know if Tulip has considered allowing notes (apart from general step notes) to be added to e.g. triggers or specific if/then statements as explanations on how the trigger or flow of if/then statements works to future designers?
I know that we are supposed to only build simplified apps but some use cases actually do require us to be a bit creative.

1 Like

@ASharp-J great point and question - short answer is yes this is very much on our radar. We have had a lot of great product suggestions regarding native ability to add comments to triggers and John actually summarized a update just the other day on this HERE