8 Replies Latest reply on Feb 22, 2009 11:04 PM by davidhead

    Value list and Script trigger

    deliciousapple

      Title

      Value list and Script trigger

      Post

      I have a value list called "Product Name", which contains the following...

      Roofing

      Siding

      Windows

      Gutters

      Insulation

      Entry Doors

       

      I have a field called x_pop (just a text field) that I have on my form, I display it as a "Drop-down list".   This field Displays Values From "Product Name".

       

      OnObjectModify is the script trigger I have set for the field x_pop.

       

      When I pick a product from the list field in x_pop, I then need a script to run, to show all records that contain that product.

       

       

      Idea's? 

       

      Thank you for any help, I am a Bento convert and the learning curve is a much. 

        • 1. Re: Value list and Script trigger
          davidhead
            

          Can I assume that x-pop is specified as a global field? If not, it should be. ;)

           

          You are correct in applying an OnObjectModify script trigger to that field. So when a user changes the value, it will trigger a script to find records of the type selected. The script that it runs can be something like:

           

          Enter Find Mode [ ]

          Set Field [ productType; x-pop ]

          Set Error Capture [On] 

          Perform Find [ ] 

          Set Error Capture [Off] 

           

          So what you are doing is to apply the selected global value to the x-pop field as a criteria for a find request and performing the find. The actual find is wrapped in a Set Error Capture to trap errors - usually no records found.

          • 2. Re: Value list and Script trigger
            deliciousapple
              

            Wow thank you David,

            It worked the first time

             

            I am a bit confused as to what Set Error Capture On/Off does, it traps errors??

             

            I have put some if statements in to perform my find, does this look ok, is there a better way?

             

            Anyway a huge thanks again for the solution it worked like a charm 

             

            Enter Find Mode []

            Set Field [Appointments::x_pop] 

            Set Error Capture [On] 

            if [Appointments::x_pop = "Roofing"]

            Perform Find [Restore]

            Sort Records [Restore; No dialog] 

            Else if[Appointments::x_pop = "Siding"]

            Perform Find [Restore]

            Sort Records [Restore; No dialog]

            Else if[Appointments::x_pop = "Windows"]

            Perform Find [Restore]

            Sort Records [Restore; No dialog] 

            Else if[Appointments::x_pop = "Gutters"]

            Perform Find [Restore]

            Sort Records [Restore; No dialog] 

            End if

            Set Error Capture [Off] 

            • 3. Re: Value list and Script trigger
              TSGal

              DeliciousApple:

               

              The Set Error Capture [On/Off] does indeed traps errors.

               

              If you search for records and no records are found, an alert pops up asking if you want to modify the find.  By setting the Error Capture On, FileMaker will stop the dialog box from appearing, and you can then check to see if no records are found.  That is,

               

              If [ Get (FoundCount) = 0 ]

                 Show Custom Dialog [ "No Records Found" ]

                 Halt Script

              End If

               

              This may not apply to you since you are using a pop-up value list, but if it were a regular field and you misspelled one of the options, you could trap for this.  Does that make sense?

               

              TSGal

              FileMaker, Inc. 

              • 4. Re: Value list and Script trigger
                davidhead
                  

                Actually there is no need for the If statements in your script. If you look again at my example:

                 

                Enter Find Mode [ ]

                Set Field [ productType; x-pop ]

                Set Error Capture [On] 

                Perform Find [ ] 

                Set Error Capture [Off] 

                 

                Can you see that the find criteria is being constructed dynamically using the existing value of x-pop with the Set Field command? Then there is no restoring of the find requests in the Perform Find step. So it may be that the error capture confused you - all you need in the first instance is:

                 

                Enter Find Mode [ ]

                Set Field [ productType; x-pop ]

                Perform Find [ ]

                 

                That script is dynamic because it can perform for any value entered into x-pop.

                With your script, you would need to edit the script every time you added to the value list.

                 

                All I added was to wrap the Perform Find step in an Error Capture to suppress the FileMaker Pro dialog that says that no records were found (if that ever happened).

                 

                Make sense? 

                • 5. Re: Value list and Script trigger
                  deliciousapple
                    

                  David you have knack for teaching.  Thank you for your clear explanations/examples.  I have it set up just as you explained and it works perfectly.

                   

                  Now I would like to have two drop-down calendar fields on my report, and search by both category and a date range.  I guess I would also use a button instead of a script trigger??

                   

                  I also need to be able to search all products at once as well.

                   

                   

                  • 6. Re: Value list and Script trigger
                    davidhead
                      

                    Thank you for your kind words. As it happens, I am a FileMaker Authorised Trainer and I have just returned to Australia from the latest Train the Trainer course for the new FileMaker Training Series materials to be released in April. Very worthwhile exercise but a long trip. ;)

                     

                    Anyway,  back to your latest question. I think you would still be able to do it using OnObjectModify script triggers. The script gets a little more complex though (obviously).

                     

                    Look at the rules for searching:

                     

                    1. if there is a product selected, find records for that product (we have done that)

                    2. if there is a start date, filter the found set down to records on or after that date

                    3. if there is an end date, filter the found set down to records on or before that date

                     

                    So I suppose that the date fields would trigger a Constrain Records command if there was a product selected but a standard find if no product was selected. I would need to construct a sample file to test what might go wrong. Are you interested in seeing a sample file? I can't post it here in the forum (grrr!) but can upload it to my website and give you a link.

                    • 7. Re: Value list and Script trigger
                      deliciousapple
                        

                       

                      So you live in Australia?  I'm out here in Seattle.

                       

                      I am very thankful for your detailed responses, I find them formated in a way that is easy to understand.  Taking a complex program and explaining it in terms that a novice would understand is no easy task.  

                       

                      And yes I would love to see a sample file, or I could send you a copy of my file, so you could have records to test.

                       

                      Thanks

                      Gene

                        

                       

                       

                      • 8. Re: Value list and Script trigger
                        davidhead
                           OK, send your file to "david at ulearnit dot com dot au" - I will update it and send it back asap.