April 29, 200223 yr 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.
April 29, 200223 yr 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]
April 30, 200223 yr 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
April 30, 200223 yr 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.
April 30, 200223 yr 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)
April 30, 200223 yr 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
April 30, 200223 yr 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!).
April 30, 200223 yr 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
April 30, 200223 yr Aha! The old Gotta-Use-Literals-With-Portals Trick! Right, Chief? Sorry, couldn't resist. Haven't seen Get Smart in ages.
April 30, 200223 yr 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
April 30, 200223 yr 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
April 30, 200223 yr 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
April 30, 200223 yr 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.
April 30, 200223 yr 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