I seem to be able to get the right functionality with GetNthRecord:
Set Field [MyLayoutTable::MyField; GetNthRecord (MyDynamicallyFilteredPortalTable::PrimaryKey;1)]
is that the right/best way of doing it?
No, I think you need to drive the focus to the portal (use go to field, or name the portal) and then pick up the data from the Portal Row [First]. The reason I think you method is suspect is because you have to use the relationship only and the records it relates to ignore the filters on the portal.
You're absolutely right. I made a mistake in calling it MyDynamicallyFilteredPortal... it's "filtered" at the relationship level only. Not with portal filters.
But i originally wanted to do what you are talking about, and put the focus on the portal (and I still would like to learn) but i can't figure out how to put the script together, so could you maybe elaborate further with a snippet? With the portal object name "MyPortal"?
Use the name box in the inspector to give your portal an object name.
Then use this script:
Go to Object ["objectNameOfPortalHere"]
Go to Portal Row [first]
Set Field [YourTable::YourField ; YourPortalTable::Field]
Commit record removes the focus from the portal. You can leave out that step if you want to leave the focus on this portal row.
And thanks Sorbsbuster - I'm just so new to scripting that I need to have it spelled out.
Hey Phil, another question to this:
When the portal is only filtered at the relationship level, doing only the third script step of your solution: Set Field [YourTable::YourField ; YourPortalTable::Field] does the same thing, since it apparently automatically chooses the first record in the relationship, and there is no portal to remove the focus from.
Is that a "good" simplification, or is it just sloppy scripting? I'm guessing sloppy?
I use that method all the time. It is an approach that ignores your portal completely as it relies on the underlying relationship. Any direct reference to a field in a related table will refer to the "first" related record. Set Field [YourTable::YourField ; YourPortalTable::Field] is just one such example. You can setup any number of calculation expressions in conditional formats and calculation fields that obey the same priniciple.
What is "first" in a set of related records depends on how you define the relationship. When you double click a relationship line in Manage | Database | Relationships, you can specify a sort order for the related table. The oldest related record will be the first related record if there is no specified sort order. If you specify a sort order, the sort order determines which record is first.
Add a little horsepower to your idea so that when the time comes in the future this will always work. At some point the idea of going to the first record will be replaced by using the second or third or...
Just put the button on the portal row. Now when it is clicked it will call a script:
Set variable $_ID to the value in the portal row
Do whatever with this variable
Sorry the context wasn't explained; what I needed to do here was to set a global field to the ID of the first portal record, from a script trigger placed on a different object than the portal itself (on modify of a pop-up that filters the portal).
Ah, so given the sorting, it's a behavior that one can actually rely on (I didn't dare assume). I think I'll be using that quite a bit, then.
Good info - Thanks