13 Replies Latest reply on Jul 17, 2017 7:34 AM by William-Porter

    Set field script step

    jjfcpa

      I have a field that will contain either a Yes or No value.  I need to find out how many have a No value.

       

      I'm doing a the following:

       

      Enter find mode

      Set field FIELDNAME to "=No"

      Perform find

       

      This results in an Error Code 5 and the get(foundcont) will return 1 record when actually NONE of them have No entered for the field.

        • 1. Re: Set field script step
          philmodjunk

          I suggest that you post a screen shot of the scripts workspace to show the exact way that you've set up this script if the following does not help you.

           

          Set field has three parts: The target field, the repetition, the calculated result. For what you want, you need to leave the repetition at it's default setting of 1. I am guessing from the error code that you put "=No" as a calculation for the repetition instead of for the calculated result. Your set field step should look like this:

           

          Set Field [TableOccurrence::FieldName ; "=No"]

           

          If you see an extra pair of [ ], then you have put "=No" into the repetition instead of as the calculated result.

          • 2. Re: Set field script step
            jjfcpa

            Here is my script steps and I think I entered it correctly.

             

            script_steps.jpg

            • 3. Re: Set field script step
              Stephen Huston

              Perform Find/Replace is a different (and incorrect) step from

              Perform Find.

              • 4. Re: Set field script step
                gofmp15

                Remove the = sign and use field = "No".

                • 5. Re: Set field script step
                  taylorsharpe

                  you are finding No's in another layout and when you return, it is a different layout with different context.  Is that what you meant to do?

                  • 6. Re: Set field script step
                    gofmp15

                    Also...

                     

                    I find it easier to create a value list called One whose only value is one. I use this instead of yes or no.

                    Then the field can be set to show yes or no via naming the field etc.

                     

                    Counting the instances of 1 is now just sum(field).

                     

                    It is a 5 second problem to rename the text label to yes or no...  and to drag the right side of the checkbox object so that the name doesn't show.

                    • 7. Re: Set field script step
                      taylorsharpe

                      Yes, Stephen... good point!

                      • 8. Re: Set field script step
                        gofmp15

                        3rd suggesstion

                         

                        Select a layout where you have the field displayed as a checkbox with Yes or No.

                         

                        Perform a find selecting No.

                         

                        Open a script and create the line Perform Find and click on Specify Find Request.  This one script step will find your NO or your Yes records.

                        • 9. Re: Set field script step
                          philmodjunk

                          "3rd suggesstion..."

                           

                          That's not one I can agree with. Stored Find criteria buries the details inside some dialogs. When you review a script, you can't see those details without stopping to open those dialogs as well as not being as flexible as the current approach. It just needs a few of those details fixed.

                          • 10. Re: Set field script step
                            gofmp15

                            I used to make the same argument about not using the single line perform find but I have since become even lazier and have begun using it almost exclusively. It's a great debugging tool since if the find worked, the perform find should also work and I don't have to worry about typos with the set fields.

                             

                            BUt in this wonderful world we have the ability to use our own choice and not tell anyone about it. 

                            • 11. Re: Set field script step
                              philmodjunk

                              and not tell anyone about it.

                               

                              but obviously not you or I as we both told people about it.

                              • 12. Re: Set field script step
                                dburnham

                                I think the change of layouts is not relevant, but the Perform Find/Replace is the wrong script step.   I'm assuming you already made that changed and my comments are directed at some other responses below.

                                 

                                The suggestion to perform the find manually and then insert the script step is a great one.  It is a technique that goes all the way back to the first version of FileMaker, perhaps a decade before Claris acquired FileMaker.  You had to do the thing before you could script it.  It wasn't until FileMaker 7 that we wer able to write those script steps explicitly.

                                 

                                I'm on the fence about whether or not to include the find or omit conditions in the Perform Find script step.  Ever since version 7, I have preferred that method because it keeps scripts from becoming unnecessarily lengthy, but the thing that I dislike about it is something that wasn't mentioned here, and that is the fact that you can't drag the find or omit conditions up or down in sequence.  Typically you want to cast a wider net and then narrow down with the omits occurring after the finds.  If you ever have to modify a Perform Find that has those items written into it, you can't do that.  You have to always create them in sequence.  So that's one reason why entering the Find Mode and specifying each find or omit with a Set Field step is preferable.   It also allows you to disable one or several of them if necessary and that's easier than re-writing the step.

                                 

                                On the other hand, if you have a script where Perform Find occurs several times, such as inside an IF/ELSEIF set of script steps, the script length gets to be a nuisance, particularly with the awful new behavior of Script Debugger in FileMaker 16,but that's another story.

                                • 13. Re: Set field script step
                                  William-Porter

                                  dburnham wrote:

                                   

                                  .... because it keeps scripts from becoming unnecessarily lengthy...

                                   

                                   

                                  Wouldn't it be great if FileMaker 17 gave us the ability to collapse logical sections of scripts? That would solve the length problem....