When are flatten collections allowed?

Good day all!

I have two questions regarding flatten collections:

First, I noticed I tried multiple times to create a flatten collection based on a collection that is derived from another flatten collection.

'Order Lines': collection ['Order Lines'] = flatten (
'Internal Order Stock' = .'Purchase Orders'* .'Order Lines'* .'This Kind'?'Yes'.'This Size'?'Yes'.'This Colli Type'?'Yes'.'Weeks'* .'Days'* .'Internal Orders'* as $ ( ) //this gives an error because Internal Orders* is a derived collection.
)
no valid 'valid key value source' found for 'value type' option 'collection'. Unexpected 'value source':
application.alan(37585, 167): - expected: 'base'
(1, 1): - but found: 'derived'

Is there any way to work around is? Or the only method is to use the base collection?

Second,

Why is it not possible to use a collection that sits a bit higher in a flattened collection? Now I first create collection B from collection A, which are essentially identical. Then I use collection B in the flattened collection.

'I' = .'Underlying'?'Purchase'.'Class Found'?'Yes'.'Orders'* .'Lines'* .'Internal Orders'* .'Lines'* .'Purchases'* .'Org/Conv matches'?'Yes'.'Packaging matches'?'Yes' as $

I did solve issue 1 by using the base union instead of flatten. .'Internal Orders'* is flatten of the following union.'Internal Orders'* .'Lines'* .'Purchases'*

The application language supports flatten only (for now) because of limitations of the webclient w.r.t. views that show entries from different collections in a single table.

It is never necessary to use flatten on a collection that is already the result of another flatten operation. You can always use the source collections directly. Once we drop support for flatten, it will be much easier to rewrite it to the alternative that we plan to provide for achieving the same goal.

The need for using a collection higher up in the hierarchy, is often indicative of a design flaw. You are effectively creating potentially thousands of duplicate entries. I can explain this in more detail/suggest improvements if you provide me with your complete application model and explain your final goal.

1 Like