Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Test for Empty Portal

Featured Replies

Is there a way to test for an empty portal before entering the portal?

Here's a sample of what I'm talking about.

[fmp-if: poral is empty]

show this number

[fmp-else]

[fmp-poral: MyPortal]

[fmp-field: MyPortal::name]

[/fmp-portal]

[/fmp-if]

Any ideas or code would be appreciated.

I try to get FileMaker to do as much of my processing for me instead of doing it through CDML.

Define a calculation field (unstored, number) in the database itself:

Is_Portal_Empty = not IsValid(Relationship_Name::Foreign_Key)

Where Relationship_Name is, obviously, the name of the relationship that the portal is based on, and Foreign_Key is the foreign key of the related DB. It doesn't necessarily have to be that field in particular, but it must be a field that will definitely have a value.

Then your CDML would be:

[FMP-If: Is_Portal_Empty.eq.1]

Show this number

[FMP-Else]

[FMP-Portal:Relationship_Name]

.

.

.

[/FMP-Portal]

[/FMP-If]

Another method is to test a field of the relationship to see if it is empty:

[FMP-If: myrel::afield .eq.]......

All the best.

Garry

Garry, I thought we had just discussed checking a field to see if it is empty with evildan. You are providing "Another method is to test a field of the relationship to see if it is empty: [FMP-If: myrel::afield .eq.]."

That is essentially the same code which evildan had tried in his earlier thread and which did not work. As was discussed, a field, when using the comparators .eq. or .neq., must be compared with a literal (cdml reference). Lungfish offers such a comparison with a literal in his code. evildan said that what finally worked for him in the earlier problem was essentially "[FMP-If: myrel::afield .ncn. ""]"

When attempting to determine via a cdml if-conditional if a field is empty or not, one is well advised to use the comparators "contain" or "does not contain", or use a literal with .eq. or .neq..

As to the example presented by Lungfish he suggests,

"Define a calculation field (unstored, number) in the database itself:

Is_Portal_Empty = not IsValid(Relationship_Name::Foreign_Key) "

While this will work, one could also use the calculation (also unstored)???

Is_Portal_Empty = case(IsEmpty(myrel::afield),0,1)

The literal "0" or "1" could then be used with the comparators .eq. or .neq.. The effect is the same as a boolean.

HI Keith,

In reply to:

As was discussed, a field, when using the comparators .eq. or .neq., must be compared with a literal (cdml reference).


Gosh, I hate to disagree with someone who otherwise validates my other suggestions, but I make extensive use of CDML comparisons without literals, e.g. [FMP-If: Fieldname.neq.], and they've never given me trouble. Usually I don't even include the official "Field:" in my FMP-If statement, unless it just ain't working. For one reason or another, Web Companion is a little flexible in the way it parses these tags.

Just a friendly FYI.

Lungfish (formerly The Bridge)

Keith,

I've used the comparison [FMP-If: field .eq.] a bit and it has always worked for me.

I did follow the discussion with Dan and I am still a little unsure why [FMP-If: field .neq.] did not work. Note that I do not like to use double negatives, hence have not used the logic this way.

Maybe worth some more testing! I will give it a go tomorrow.

All the best.

Garry

Hey Lungfish and Garry, thanks for the input. I've never had it work without the literal.

I don't mind douible negatives if they work. Same with double positives (Yeah, right!).

I've been doing some experimenting (FMP5.5v2 OS X)???

[FMP-If: field .eq.] and [FMP-If: field .neq.] work with standard fields.

They do not work with related fields!

'Get Smart' is about to start on TV so I will have to stop experimenting for the time being.

Catch you all later.

Garry

Aha! The old Gotta-Use-Literals-With-Portals Trick! Right, Chief?

Sorry, couldn't resist. Haven't seen Get Smart in ages. smile.gif

OK, I'm much smarter now. I have a plan. (Missed it by thaat much!)

Create a calculated field which is simply one of the related fields. Place this field on your layout. Now test this field with:

[FMP-If: mycalcfield .eq.]No Portal Rows

[FMP-Else]

[FMP-Portal: myportal]

portal fields here

[/FMP-Portal]

[/FMP-If]

Hope this is of use.

Garry

Hi, I agree that the way to do this is in the database.

I use the 'empt portal' test for a news stories page, which shows a search return on records: 'latest news', 'more news', 'industry news', 'social news'. Each of these has a portal with the stories. If there are no stories in that section, it doesn't display the heading.

In the database, I have a calculation field 'counter' that counts the related records in the portal and I then do a find based on counter>0

like this:

"http://mydomain.com/FMPro?-db=news&-format=news.htm&-error=news.htm&-lay=layout1&-sortfield=appear_order&-sortorder=ascending&-op=gt&counter=0&-op=eq&appear=main_newspage&-find"

I kinda like to use calculations rather than 'IF"s because you can index them.

regards, Jeff

After having demonstrated the use of cdml for this, I must confess that I too use calculated 'flags' for checking the presence of rows in a portal.

Good to have a couple of ways to skin a cat wink.gif

All the best.

Garry

  • Author

I will try to use calculated fields to accomplish the portal test.

FYI, for anyone dealing with portals/CDML, In my tests, anything within the portal tags is just ignored if the portal is empty...

which is why the following code will not work all the time.

[fmp-portal: portal]

[fmp-if: portal::field .neq.] [fmp-field: portal::field2] [fmp-else] #2 [/fmp-if]

[/fmp-portal]

The test is only conducted if the portal contains a value. Seems silly that I didn't matter before the latest version update, and now it does, but hey, I'm not going to argue with the experts.

Secondly, but more importantly, I wanted to thank you all for your imput regarding this matter. I really do appreciate all of the help I get from this site. Honestly I would be lost without all of your insight.

I think I've worked it out as well:

[fmp-if: keith::goes_to_sleep.eq.]

The issue will get resolved

[fmp-else]

Error. Error. Error.

[/fmp-if]

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.