evildan Posted April 29, 2002 Share Posted April 29, 2002 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. Link to comment Share on other sites More sharing options...
The Bridge Posted April 29, 2002 Share Posted April 29, 2002 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] Link to comment Share on other sites More sharing options...
Garry Claridge Posted April 30, 2002 Share Posted April 30, 2002 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 Link to comment Share on other sites More sharing options...
Keith M. Davie Posted April 30, 2002 Share Posted April 30, 2002 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. Link to comment Share on other sites More sharing options...
The Bridge Posted April 30, 2002 Share Posted April 30, 2002 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) Link to comment Share on other sites More sharing options...
Garry Claridge Posted April 30, 2002 Share Posted April 30, 2002 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 Link to comment Share on other sites More sharing options...
Keith M. Davie Posted April 30, 2002 Share Posted April 30, 2002 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!). Link to comment Share on other sites More sharing options...
Garry Claridge Posted April 30, 2002 Share Posted April 30, 2002 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 Link to comment Share on other sites More sharing options...
The Bridge Posted April 30, 2002 Share Posted April 30, 2002 Aha! The old Gotta-Use-Literals-With-Portals Trick! Right, Chief? Sorry, couldn't resist. Haven't seen Get Smart in ages. Link to comment Share on other sites More sharing options...
Garry Claridge Posted April 30, 2002 Share Posted April 30, 2002 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 Link to comment Share on other sites More sharing options...
Jeff Spall Posted April 30, 2002 Share Posted April 30, 2002 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 Link to comment Share on other sites More sharing options...
Garry Claridge Posted April 30, 2002 Share Posted April 30, 2002 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 All the best. Garry Link to comment Share on other sites More sharing options...
evildan Posted April 30, 2002 Author Share Posted April 30, 2002 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. Link to comment Share on other sites More sharing options...
Keith M. Davie Posted April 30, 2002 Share Posted April 30, 2002 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] Link to comment Share on other sites More sharing options...
Recommended Posts
This topic is 8196 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now