Steve,

One way to do it is a bit convoluted, but will do what you want:

$Params:=split string($YourText;".")
Case of
 :($Params.length=1)
$collection:=$employees[$Params[0]]
:($Params.length=2)
$collection:=$employees[$Params[0]] [$Params[1]]
:($Params.length=3)
$collection:=$employees[$Params[0]] [$Params[1]] ]] [$Params[2]]
:($Params.length=4)
$collection:=$employees[$Params[0]] [$Params[1]] ]] [$Params[2]] ]] [$Params[3]]
End case

Not pretty, but effective...

Cheers,

Lahav



-----Original Message-----
From: 4D_Tech <[email protected]> On Behalf Of Steve Slanec via 
4D_Tech
Sent: Monday, May 11, 2020 10:04 PM
To: [email protected]
Cc: Steve Slanec <[email protected]>
Subject: Generic code for entity selection projection

I'm trying come up with generic code that produces a projection from an entity 
selection, and I think must be missing something obvious.  I’d like to perform 
the following statement:

$collection:=$employees.company.country

But as generic code. I want to be able to pass the ORDA path “company.country” 
as a text variable so that I can change it at runtime.

Obviously, using square bracket notation doesn’t work because square brackets 
for entity selections are used for indexes:

$collection:=$employees[“company.country”]  // Syntax error

So how can I do this?

I guess I could write a method that splits the ORDA path into tokens, examines 
each token individually, and traverses through relations if the token kind is a 
“relation" until we get to the last token, whose kind must be “storage".  But 
I’m hoping I’m just being ignorant - it seems like a lot of work for doing what 
object notation does so simply and elegantly.

Using 4D v18, macOS 10.14

Thanks for any advice!

- Steve



Steve Slanec
Slanecon Digital

**********************************************************************
4D Internet Users Group (4D iNUG)
New Forum: https://discuss.4D.com
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************
**********************************************************************
4D Internet Users Group (4D iNUG)
New Forum: https://discuss.4D.com
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to