8 Replies Latest reply on Feb 28, 2014 7:46 AM by rmittelman

    Popover Help

    rmittelman

      I need a bit of help to wrap my head around how to implement a popover. Here's the specifics:

       

      I used the Contacts starter solution, which has a cool popover when you view a customer detail record. There's an "Email" popover button, and it displays a simple popover with its own 2 buttons, one for "Email Work" and one for "Email Home". As expected, clicking either does the proper action to start an email.

       

      My solution doesn't use those 2 fields (Work Email and Home Email). Instead I use a "Communications" table to contain all the emails and phone numbers for the contact records. Realistically, there should be 1 - 3 emails for a contact.

      What I would like to know is how I would dynamically build the popover content so it would know what email addresses exist for the contact and display them. Ideally a check box set, so the finished result would be like:

       

      [ ] Work: Me@MyJob.com

      [ ] Home: Me@MyHouse.com

       

      ------------------

      | Send Email |

      ------------------

       

      The "Send Email" button would run the script so it would send an email to one or both addresses, depending on checked state.

       

      Is it possible to dynamically load a popover to work like this? Any examples available?

       

      Thanks...

        • 1. Re: Popover Help
          erolst

          rmittelman wrote:

          What I would like to know is how I would dynamically build the popover content

          You have a relationship, so why not use a totally dynamic portal … plus a fancy “tick”box.

           

          See here for a small sample:

          • 2. Re: Popover Help
            rmittelman

            Hi @erolst, this is pretty much exactly what I was picturing.  Now I just need to figure out what you are doing here.  The ManageSelection script is obviously the heart of this, so I have some questions about it (actual questions bold).

             

            1: The "select" part.

            It looks like you are setting $$list by testing whether or not the particular clicked-on item is at the beginning, middle or end of list, then removes it if so, and adds to beginning if not, right?

             

            $$mail: I've never used ExecuteSQL (although I've used SQL itself many times in other environments). I see you're building an IN clause there.

            I'm unfamiliar with the "\" syntax, is that a concatenation thing

            The actual execute confuses me: You include the WHERE in the SQL command, and again at the end in the "arguments" member. I don't get that

             

            You are refreshing the popup after setting $$list and before setting $$mail. Why, and how do you update the tick?  I see <<$tick>> in the portal, but can't find anywhere where you set it.  How do you make that a tick mark?

             

            2: The "create" part.

            You're setting $$EXIT to 1 then closing popover then setting to "".  Please advise what that does.

             

            The rest seems self-evident.  I guess you are using $$ variables so the chosen items will be remembered between popover invocations, unless you click Cancel.

             

            Just out of curiosity, what is the advantage of using all of this versus adding a field to the Communication table and just set that to true or false, and use to control the tick? 

            I realize that would make the choice of each item permanent (unless "cancel" caused the field to be set to false for all portal records).

            I'm not second-guessing you here, I really want to know the relative merits of one vs. the other.

             

            Thanks again for such a quick and detailed response.

             

            EDIT:  Oh, forgot to ask:  What is the purpose of the "children" table with cartesian join?

            • 3. Re: Popover Help
              erolst

              To answer your final question first: Using $$s to hold selection lists …

               

              a) has less overhead than adding a field for just a temporary purpose.

               

              b) is multi-user friendly; a field would be an attribute of the record, so if you and Joe Schmoe from Sales and Suzy Creamcheese from Marketing all decided to send a mail to the same customer and checked different addresses, the e-mails for the three of you would be sent to all checked addresses, regardless of who checked them. OTOH, for an address to be in your $$list is an attribute of your current selection, and yours alone.

               

              c) by the same token, it's easier to clean up after the fact (as you have already noted).

               

              d) is more fun (which is of course a purely personal perspective and preference), and helps discovering the breadth of the toolset at your disposal.

               

              For the rest:

               

              1. 1. Yes

               

              1.2 the "\” is an escape “thing” (character), as in “make SQL accept the following character, even it it's on the SQL black list”. (To concatenate in FQK, use ||).

              (The usual caveat applies: use CFs to guard your SQL statements against name changes of FileMaker fields and wrap them pre-emptively into escape characters).

               

              As to WHERE: there is only one WHERE in the buildup of the select statement string, which then is passed to ExecuteSQL(). Don't know where you saw another one.

               

              1.3. The tick is a unicode character set in a local variable (a not officially sanctioned, but highly enjoyable use of same) that is defined in the Conditional Formatting of the portal field. (You have to ungroup/“unbutton” the portal elements to be able to inspect the CF.) Thus the portal needs to be refreshed in order to redraw the tick (or nor, as it were).

               

              2.1 If not $$EXIT, you cannot close the popover. So set $$EXIT to 1 (or True), close the popover, then reset (delete) the now unnecessary $$.

              I guess you are using $$ variables so the chosen items will be remembered between popover invocations

              2.2. Actually, it's between script invocations, since you're using one and the same script all the time. The $$s are also cleared when you use Send/Save/whatever, since the list has done its duty, so to speak.

              EDIT:  Oh, forgot to ask:  What is the purpose of the "children" table with cartesian join?

              An experimental leftover, not pertinent to the popover demo.

              1 of 1 people found this helpful
              • 4. Re: Popover Help
                rmittelman

                Ok, in no particular order:

                 

                2.1:  Explanation makes sense, but why doesn't the Close Popover command work regardless of value of $$EXIT?

                2.2:  Yes, I agree, that's what I meant.

                1.3:  Way cool. How did you discover that particular unicode character? In Character Viewer?  Could it also have been a graphic with the "hide object when" property set?  I think I get the refresh object thing, it's similar to when I want to reorder my portal records by the record's sequence number. You change the sequence number and refresh the portal to get it to redisplay, right?

                1.2:  It looks like you're escaping the quote character, which makes sense. But why couldn't you just say:

                "Select.... WHERE _pk_CommunicationID IN (1, 2, 3)"?  Why do you need to include the quotes at all?  I'm sure this relates to the "usual caveats" explanation, but that just made my head spin.  Not to be obtuse, but what is FQK?

                 

                The "Where" question:

                In your script setting $$mail, you have the following calculated value:

                 

                Case (

                 

                  not IsEmpty ( $$list ) ;

                 

                Let ( [

                    ~idlist =  "(" & Substitute ( $$list ; ¶ ; "," ) & ")" ;

                    ~sql = ( " SELECT communication FROM Communication WHERE \"_pk_CommunicationID\" IN " & ~idlist )

                    ] ;

                 

                   ExecuteSQL ( ~sql ; "" ; ", " ; ~idlist )

                 

                   )

                 

                )

                 

                So ~idlist is the IN stuff, and it's concatenated to ~sql, so therefore ~sql is a complete SQL statement.  But in the ExecuteSQL statement, ~idlist is included as the last parameter also.  It seems to me it's mentioned twice in the ExecuteSQL command, and I was wondering why.  Since arguments are optional, wouldn't it work just as well without that last parameter?

                 

                Oh, one more thing:  There may be a bug in the logic setting $$list.  When I select all 3 items, only 2 of them show on the custom dialog. Which 2 depends on the order they were selected.

                 

                Thanks again for following up...

                • 5. Re: Popover Help
                  erolst

                  2.1 Because the popover has an OnObjectExit trigger that looks for the value of $$EXIT; closing the popover also triggers it, regardless whether you click outside of the popover or use the script step. This behaviour lets you clearly define your “exit strategies” (so to speak).

                   

                  FKL = typo; should read FQL, aka FileMaker (implementation of) SQL

                   

                  1.2 To be exact: I'm escaping the quotes within the FileMaker string, so they in turn allow the use of a name with a leading underscore in the SQL syntax. Well, that's the price you have to pay when you mix'n'mingle different languages with more or less abstraction being involved …

                   

                  WHERE: the query started out one way, then went on a different course, with the end result that the (now) unncessary value parameter is still there because I forgot to delete it. While it may be confusing, it didn't hurt in this case, because if the SQL interpreter doesn't find a ? in the statement, it doesn't look for any parameters.

                  rmittelman wrote:

                  Oh, one more thing:

                  Very funny …

                  There may be a bug in the logic setting $$list.  When I select all 3 items, only 2 of them show on the custom dialog. Which 2 depends on the order they were selected.

                  You may want to enlarge your custom dialog … or substitute the ¶s with ,s to make it fit. This was originally intended for an (imaginary) pizza order system, which is why the CD displays numbers from an (equally imaginary) menu. In your case it may make more sense to display $$mail (which already is a comma-delimited list), or forego any displays and simply prepare your meal mail.

                   

                  1.3 Yes, you could also use Hide Object, though I think that would also require a refresh.

                   

                  Unicode Viewer (one of probably very many, but this one's a real beaut IMO): http://unicode-table.com/en/

                  1 of 1 people found this helpful
                  • 6. Re: Popover Help
                    rmittelman

                    Thanks again for the response.  You are right, increasing the height of the dialog revealed the last item in the list.  This is surprising to me that a custom dialog doesn't automatically draw itself big enough to display the number of lines of text you give it.

                     

                    Now I see... FM doesn't allow underscores in a SQL command.  Didn't know that.

                     

                    What I was really curious about was the entire paragraph about "usual caveat applies".  Could you explain that concept about protecting your SQL against field name changes?

                     

                    Thanks again for all of your help.  This is a real education for me.  Coincidentally, this thread occurred very quickly after another of mine where I discovered the concept of embedding variable-setting code inside of conditional formatting.  This is a way-cool technique.

                    • 7. Re: Popover Help
                      erolst

                      rmittelman wrote:

                      What I was really curious about was the entire paragraph about "usual caveat applies".  Could you explain that concept about protecting your SQL against field name changes?

                      I could, but there are people who can do this better than me (hard to believe as that may sound …). Here is a link you will find interesting (as is the entire site):

                       

                      http://filemakerhacks.com/2012/05/13/fm-12-executesql-robust-coding-part-1/

                      rmittelman wrote:

                      Coincidentally, this thread occurred very quickly after another of mine where I discovered the concept of embedding variable-setting code inside of conditional formatting.  This is a way-cool technique.

                      The really cool thing is that you don't have to use global variables, but can use local variables to maintain a per-record state (native or related record, as my sample shows): I read this first in an article by (I think) Josh Ormond, but I cannot find the URL for that…

                       

                      Also, you can use this technique everywhere in the Calculation Engine; the artful part here is to find a spot that is evaluated at the right time (which could very well be the Tooltip calculation, depending on what you plan to do); by the same token, it lets you write recursive code outside of a Custom Function, using just a plain calc field and a workaround to allow the calculation to refer to itself (as a field).

                       

                      As I said, discovering the toolset and using alternative methods for the same result is half the joy of programming (the other half is to get the frigging code running in the first place … )

                       

                      Happy FileMak(er)ing!

                      • 8. Re: Popover Help
                        rmittelman

                        Everything seems to be working perfectly.  I tried always having a value in the "tick" textbox and making it invisible if item not in $$list, but couldn't get it to work.  Just ended up using your method of setting $tick.

                         

                        I have one more issue, which I don't know enough to solve properly.  My relationship between contacts and communications allows me to add records through the relationship.  Therefore, on my main communications portal, I can add a new phone number or email.  However, on the current "pick list" portal, that ability makes for complications, not the least of which is the empty portal row at the bottom.  I had hoped to modify the behavior when opening the popover, but it seems the permission is attached to the relationship, not the portal.  I couldn't find any way to edit the relationship in a script step.  As a work-around, I added another table instance of Communications, and this one told not to allow creation of records.

                         

                        Is there a better way to do this, such as a way to prevent adding records on a particular portal?  Or would the best thing be to remove that permission entirely and script the adding of new child records?

                         

                        Thanks...

                         

                        Follow-up:  Never mind, I scripted the adding of new records and turned off allowing adding records through the relationship.  All works perfectly. Thanks @erolst!