Test for Empty Portal
Hello fellow filemakers,
Hopefully this will be simple; I want a script to test if a portal is empty.(no rows) Seems like a simple request but I can't figure out how to do it. Any suggestions?
That's exactly what I meant.
Say you have three related records that would show in the portal, but the filter in portal set up prevents them from showing. In that case, the portal will appear empty, but IsEmpty ( relatedTable::Primarykey ) will bypass the filter and return false. Thus, you have a portal that is empty, but the data level reference we usually use will not tell us this fact.
You want to check the portal empty
So make a script that checks, Not Isempty(PK_ID)
and this PK_ID is the primary key and must comes from the portal relationship.
Careful, Atauf's method is good only if this portal isn't empty due to a portal filter hiding some related records.
If PK_ID is a field of type number, you can also simplify the expression to just:
When you look to related records it does not look through a portal - it looks at the relationship. If there is a related record, it would find it regardless of portal filter.
Were you meaning something else, Phil?
I think Phil was suggesting the difference, Dave, script aways sees all related records regardless of portal filtering.
Thanks, Phil. So Dave, if portal filtering is involved, let us know. You can determine whether a filtered portal is empty as well but it requires (AFAIK) walking through the rows, testing for empty then exiting on last row or when condition is met.
From a recent issue I experienced, I think you can use Go To Portal row [first] and trap for an error with get ( LastError ).
Very cool. Thanks to everyone. Awesome support. I don't know why i became so confused with this; I guess spending 6 hours setting up report layouts kinda turns you brain to mush. After I posted the original question, i went back to my script and instinctively went to test for the same conditions that the portal uses to display the records. Duh. Moving on. -DJ
Retrieving data ...