Tip : Return to exact portal position after leaving and returning to a layout.
Here is a neat tip to return to the EXACT positioning of the portal rows, rather than ending up at the top / bottom after changing something
This is very handy if you leave the layout and return to it via a script, especially if editing a record in the middle of a portal.
What it does is, gets the top most pixels of the portal, then gets the top most pixels of the first occurrence of the field, even if its not on screen, the position is returned correctly, hence the magic works... It then loops down until the top most pixels of the field, match the top most of the portal and uses the count to return what row you are on.
How to achieve it...
1. Give your portal an 'object name'
2. Give any field on the portal an 'object name'
Next is only if you are editing a field directly on the portal, which you want to perform a script, otherwise call the script via a button as normal.
3. Use onObjectSave to trigger the start the script, (this prevents it triggering if you don't change anything)
4. At the start of this script, set a variable to store the current portal row $actual_row = [ get(portalrownumber) ]
5. Again at the start of this script, set a variable :
// Find the top most pixels of the named object (portal) - added here so it doesn't need to repeat.
portal_top = GetLayoutObjectAttribute ("YOUR portalname as in step1" ; "top" ) ;
// Call the custom function to loop through the rows to see which row is closest to the top.
GetTopPortalRow ( portal_top ; "YOUR field name as in step 2" ; 1 ) +1)
6. Add the custom function below
Custom Function :
GetTopPortalRow [ portaltop ; objName ; counter ]
Case (IsEmpty(portaltop) or IsEmpty(objName) or IsEmpty(counter) ; 0 ;
Let (objTop = GetLayoutObjectAttribute (objName ; "top" ; 1 ; counter ) ;
Case ( GetAsNumber(objTop) ≥ GetAsNumber(portaltop) ; counter - 1 ; counter ≥ 500 ; "err" ; // Specify your own cut off if required
GetTopPortalRow ( portaltop ; objName ; counter + 1 )
) // End Case
) // End Let
) // End Case
Then perform all your script steps as required..
Then at the end of your script after returning to the original layout, use :
Edited to include info in the following posts below
Go to Portal Row [Last]
if [$top_row ≠ "err"]
Go to Portal Row [No dialog ; $top_row]
Go to Portal Row [No dialog ; $actual_row ]
Credits go to Fabrice Nordmann and Agnès Barouh for the idea on this custom function, since it is based of a similar function published on Brian Dunning's website
I thought I would share this one, something I have been trying to achieve for some time, to keep things consistent and it works a treat !