11 Replies Latest reply on May 31, 2012 5:24 PM by BruceRobertson

    My script to navigate to appropriate layout doesn't work...

    m.bodily.consulting

      I was wondering if you folks could help me get this script right. I've attached a screen capture of the script.

      I want to go to the "FixBook" layout under these circumstances:

      1. if there is data in the field "Edit notes" AND
      2. the "Fix" field is checked "yes" (this part wasn't written into my script)

      ELSE I want to go to the "Catalog" layout.

       

      Currently it keeps opening to the "Catalog" layout even though there is data in the Edit Notes field AND the Fix field is NOT checked as fixedScript_FixBook.png.

        • 1. Re: My script to navigate to appropriate layout doesn't work...
          Vaughan

          Not sure what your expect the GetAsBoolean() expression to do but it's probably not doing what you think.

           

          To see whether there is data in the Master::Edit Notes field, use the expression

           

          not IsEmpty( Master::Edit Notes )

           

          Since the master notes field is EITHER "empty" or "not_empty" the Else If expression is redundant, so replace it with a simple Else step.

          • 2. Re: My script to navigate to appropriate layout doesn't work...
            thomas_staehli

            Vaughan is right. In fact, GetAsBoolean returns 0 when you give a string as parameter (even if that string is "yes" or "true" ). You just need to modify your conditions with a valid test and you'll be fine.

            • 3. Re: My script to navigate to appropriate layout doesn't work...
              m.bodily.consulting

              Thanks for the help, but I've noticed another problem...

              It seems FM defaults to remembering the last active record, so when I run my "FixBook" script it only recognizes the record which was last active. If this record IsEmpty (Master :: Edit Notes) than the "No books need fixing" dialog box comes up. This is not what I want my script to do, I want it to look at the Edit Notes field in ALL records (not just the active record).

              I want to apply the fix (whatever it may be) to the layout's script trigger because this problem happens when I navigate to the layout from another layout AND when I use the script in button form ON the FixBook layout. Would OnLayoutKeystroke be a logical place to apply the trigger?

              Here is my script:

              Script_FixBook5.28.png

              • 4. Re: My script to navigate to appropriate layout doesn't work...
                erolst

                FM doesn't “remember” the last active record; it is just that your script runs in a specific context, which, among other things, is determined by the currently active record, no matter how you got there, and of course the current layout. If in that context Master::… is the table of the layout, only the Edit Notes field in the current record is examined. If it is a related field, only the Edit Notes field of the first related record is examined.

                 

                To check on all records in the Master table, you could create a cartesian relationship from the TO your layout is based on (is it Master?) to another TO of Master and check with "not isEmpty ( List ( Master_selfJoin::Edit Notes ) )”. Do the same with the Fix field when you come around to integrate it into your script. This will work if you simply check on empty/not empty, because a non-empty list means that there is at least one record with a non-empty field. If the Fix field can hold "Yes" or "No", you need to check with Position or PatternCount if the string is present in the list.

                • 5. Re: My script to navigate to appropriate layout doesn't work...
                  m.bodily.consulting

                  ...what is TO?

                  The Master table holds all records which have the Edit Notes & Fix fields.

                  I'm not sure I follow you on how I would check all records...would you mind elaborating?

                  I'm working on a Windows platform, FMP 11.

                  • 6. Re: My script to navigate to appropriate layout doesn't work...
                    erolst

                    A TO is short for table occurrence, which is an instance of a base table. When you open the Manage Database dialog, the names on the first tab (Tables) are your base tables. The objects on the third tab (Relationships) are TOs, which you use to define relationships. You can create any number of TOs for a base table and define relationships between TOs of different tables (or even the same one). When you create a table, a first TO with the same name as the table is created automatically by FM.

                     

                    The Help System has a lot to say about defining relationships and (no pun intended) related themes. Be aware, though, that the Help and the User Interface often speaks of “table” when in fact it should read “table occurrence”; it can all be a bit confusing …

                     

                    There is so much more to say about TOs, layouts and context, but that's enough elaboration ;-). Let's focus on what you want to achieve: determine if there any fix-worthy books or not, then go to the layout appropriate to the result of your search, find some or all books and display one or the other message.

                     

                    What you are doing in any case is switch to a layout other than the one you're on when the script commences, so why not invert the logic? Go to your FixBook layout first and do the search there; IF the search succeeds, perform the rest of the if section of your script (except switching to the FixBook layout); ELSE perform the else section.

                     

                    Since in this version of the script you wouldn't know beforehand if there are fix-worthy books, you need to insert a Set Error Capture before the Find step. This suppresses the dialog that appears if no records (books) were found, and lets you put in your own logic to handle the “error”. Read about it in the Help, but this is the basic form: […] Set Error Capture [On] - Find [] - IF [ Get ( FoundCount ) > 0 ] do stuff ELSE do other stuff.

                     

                    Hope this helps; if all else fails, post your database.

                    • 7. Re: My script to navigate to appropriate layout doesn't work...
                      BruceRobertson

                      Your script example includes a step Perform Find( restore)

                       

                      It will help you (and others trying to help you) to understand your script if you do NOT use "perform Find(restore)" but instead use explicit scripted finds.

                       

                      example:

                       

                      Enter find mode

                      set field ( contacts::city; "Melbourne")

                      Perform Find

                      • 8. Re: My script to navigate to appropriate layout doesn't work...
                        Vaughan

                        Thomas Staehli wrote:

                         

                        Vaughan is right. In fact, GetAsBoolean returns 0 when you give a string as parameter (even if that string is "yes" or "true" ). You just need to modify your conditions with a valid test and you'll be fine.

                         

                        Interestingly, GetAsBoolean( True ) returns 1. Note the lack of quotes.

                        • 10. Re: My script to navigate to appropriate layout doesn't work...
                          m.bodily.consulting

                          Bruce,

                          I looked at my Find step and noticed it wasn't searching in the fields I intended. So it turned out nothing was wrong with the script structure it was that Find step!! From now on I might do what you suggested above if it has no effect on script running time or functionality.

                          • 11. Re: My script to navigate to appropriate layout doesn't work...
                            BruceRobertson

                            There will be no difference in script run time.