Portal container drop – get id

 

This weeks article is a quick tip on how to get the correct id of the portal row when dropping on a container field.

In this example, records from the ‘Sub’ table are displayed in the ‘Main’ table in a portal.
In the ‘Sub’ table there is a field with a unique id.

If you now call a script by a button click in a portal row, you can simply set the id of the record in the script by

Set Variable [ $id ; Value: Sub::id ]

 

However, this is not possible if you drop a file on a container field and execute a script via script trigger ‘OnObjectModify’ in which you want to use the corresponding ID of the record.
In this case you would always get the id of the record of the first portal row.

But with a little trick you can get the Id of the current record in a very simple way.
The container field gets a calculated value with the simple calculation

Let (
[
$$portalId = id
] ;

Container

)

 

We make use of the property of the ‘Let’ command to set a (global) variable.
The calculation simply sets the id of the record into the variable $$portalId when the container field is changed and keeps the value of the container field.

Bildschirmfoto 2021 01 30 um 16 41 23

It is essential to remove the checkmark from ‘Do not replace existing value of field (if any)‘ to get the actual id whenever the container value changes.

If we now place a script trigger ‘OnObjectModify’ on the container field, we can now query the $$portalId variable in a script and get the correct record id for further use.

Bildschirmfoto 2021 01 30 um 17 02 35

With this you can now address the correct data set in the script for further functions.
For example open a card window and search with the Id to display the sub table record to allow further input.
Afterwards we just clear the $$portalId again.

You have any questions? Feel free to send me an email, I’ll try to answer as soon as possible.