7 Replies Latest reply on Aug 25, 2011 12:45 PM by djtechwise

    Test for Empty Portal

    djtechwise

      Title

      Test for Empty Portal

      Post

      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?

        • 1. Re: Test for Empty Portal
          Abhaya

          Hi

          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.

          Thanks

          • 2. Re: Test for Empty Portal
            philmodjunk

            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:

            Not YourTable::PK_ID

            • 3. Re: Test for Empty Portal
              LaRetta_1

              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.

              • 4. Re: Test for Empty Portal
                philmodjunk

                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.

                • 5. Re: Test for Empty Portal
                  LaRetta_1

                  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.

                  • 6. Re: Test for Empty Portal
                    philmodjunk

                    From a recent issue I experienced, I think you can use Go To Portal row [first] and trap for an error with get ( LastError ).

                    • 7. Re: Test for Empty Portal
                      djtechwise

                      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