8 Replies Latest reply on Dec 9, 2009 7:09 AM by mrvodka

    selecting layouts in a script by calculation

    imgaryshap

      Title

      selecting layouts in a script by calculation

      Post

      Hello,

       

      I'm a FMP 8 user on MAC.

       

      I have script that executes a sort via date range.  

       

      when i select the particular sort, it takes me to a layout to input the dates.

       

      this works fine.

       

      I want to add a button where i can simply sort all records, thus bypassing the need to enter dates.

       

      now - no matter what the sort is that i'm looking for (any number of fields), the scripts all take me to the same "Date Range" page.

       

      I simply hit "continue" and the sort continues with the entered dates, and takes me to the proper layout respective to the sort I'm running.

       

      when i try to show all records, and bypass the entry date, that's where things go wrong.  

       

      I'm wondering if there is either calculation to choose layouts, or is there a calculation where if both "to" and "from" date fields are blank, then "sort all records."

       

      any ideas?

       

      thanks!

       

      -G.

        • 1. Re: selecting layouts in a script by calculation
          philmodjunk
             I sounds like you are clicking a button that runs a script and this script takes you to your Date Range layout. You'll need to locate this script and edit it to remove the steps that currently take you to the date range layout.
          • 2. Re: selecting layouts in a script by calculation
            imgaryshap
              

            but i want to go to the date range layout.

             

            is there not a calculation, maybe not a layout change, that would work?

             

            i.e., in my script - Insert Calculation:  If (IsEmpty(Field A) and IsEmpty(Field B);{something to show all records}; Field A & "..." & Field B )

            • 3. Re: selecting layouts in a script by calculation
              philmodjunk
                

              I'd add a button on the date range layout that runs a completely different script that skips the date range part of the find or...

               

              use

               

              If [IsEmpty (yourtable::yourdatefield)]

                 Do a "no date range" find here

              Else

                Do the find you already have here

              End If

              • 4. Re: selecting layouts in a script by calculation
                imgaryshap
                  

                I got the results I'm looking for with the following:

                 

                 Case(
                IsEmpty(Field A) and IsEmpty(Field B); "*";
                IsEmpty(Field A) and IsValid(Field B); "≤" & Field B;
                IsValid(Field A) and IsEmpty(Field B); "≥" & Field A;
                IsValid(Field A) and IsValid(Field B); Field A & "..." & Field B
                )

                 

                what's the language and commands in a script so that if there are no records that match the criteria in the performed search, a custom dialogue box comes up, and the button takes you back to the original date entry page?

                 

                 



                • 5. Re: selecting layouts in a script by calculation
                  mrvodka
                     Turn Error capture on and then you can grab the error code after the perform find and do what you wish from it. Look at FileMaker's help for list of error codes.
                  • 6. Re: selecting layouts in a script by calculation
                    imgaryshap
                      

                    and do what?

                     

                    is there a calculation i.e., If Error Code=xxxxxx, then custom dialogue?

                     

                     

                    • 7. Re: selecting layouts in a script by calculation
                      philmodjunk
                        

                      You can also just use

                       

                      If [Get ( FoundCount ) = 1 /* only one record */]

                        Go To Layout [Form Layout designed to just display the fields of one record]

                      Else If [get ( FoundCount ) > 1 /* Many records found */]

                        Go To Layout [List view layout listing all the records found]

                      Else

                        Show Custom Dialog ["No records were found"]

                      End If

                       

                      With this approach you don't deal with why there were no records found which may or may not be a better approach depending on what you want to see happen here.

                       

                      If you want to distinguish between "no records match criteria" and "Invalid criteria", look up Error Codes in the help system and you'll see a table of all possible error codes.

                      • 8. Re: selecting layouts in a script by calculation
                        mrvodka
                          

                        It had seemed as though you wanted specific messages for specific actions so I didnt post an option to just give a blanket message if no records were returned for any reason, which Phil has shown you how to do.

                        Instead, if you indeed wanted to be specific, you would capture the error and then proceed based on each error on what to do using some If/Else statements.
                         

                        Set Error Capture [ On ]
                        Perform Find [ ]
                        Set Variable [ $error; Get ( LastError ) ]
                        Set Error Capture [Off]

                        If [ $error = 400 ]
                          Show Custom Dialog [ "Find criteria empty" ]
                        Else If [ $error = 401 ]
                          Show Custom Dialog [ "No matching records" ]
                        Else If [ $error = 508 ]
                          Show Custom Dialog [ "Invalid value" ]
                        Else
                          Go to Layout [ "List of Record" ]
                        End If