8 Replies Latest reply on Dec 16, 2009 4:36 PM by comment_1

    Help needed to understand how to format script

    HugoLidia

      Title

      Help needed to understand how to format script

      Post

      Using Windows XP SP· & FMP 10

       

      New to filemaker I am frustrated by not being able to simply hand code a script and being forced to use the Script Manager.

       

      For instance, using an "If" statement, the format is If(test; result1; result2).  How does one add the semi-colon to be able to delimit the test from the result1 and result2???

       

      This is what I think it should look like.............. 

      If [Get(ActiveFieldContents <> " "]; // if the record is not blank, show the appropriate tab control of selected policy

         perform script(GoToPolType)

         perform script(SelectedPolicy);

                                                       // otherwise, do nothing, User can add new record.

      Endif

       

      But I can only enter (and this does not work) ....... 

      If [Get(ActiveFieldContents <> " "] // if the record is not blank, show the appropriate tab control of selected policy

         perform script(GoToPolType)

         perform script(SelectedPolicy)

      Endif

       

       

       

      I can see that the script manager tool forces valid syntax to be used and valid field names, as these have to be chosen from the drop down lists, so I guess I am missing something oh so simple, but not expalined in the various developer books I have.

       

      Somebody tell this dunce where he is going wrong and put me out of my misery!

       

        • 1. Re: Help needed to understand how to format script
          comment_1
            

          HugoLidia wrote:
          For instance, using an "If" statement, the format is If(test; result1; result2). 

          I am afraid you are confusing the If[] script step with the If() function. The syntax you mention applies to the function, in a script it's simply:

           

          If [ test ]

          # ... script steps to perform if the test returns true ...

          End If

           

          so your script should indeed look like your second example. If it doesn't work, then it must be for another reason.

          • 2. Re: Help needed to understand how to format script
            comment_1
              

            BTW, I don't know how siginificant this is, but there is a space between the quotes in your test expression. IMHO, it's better to use the IsEmpty() function here.

             

             

            • 3. Re: Help needed to understand how to format script
              HugoLidia
                

              Yep, that's why I was confused, the script syntax is correct therefore.  But it still doesn't explain why one can't enter freehand text, to include comments in the script.

               

              On your second point, why is it better to use the IsEmpty() function as compared to testing to check that the value is not blank?

              Should my script read :

              If [IsEmpty(policies:: policyno) = 0 ]

                 Perform Script (GoToPolType)

              EndIf

              • 4. Re: Help needed to understand how to format script
                comment_1
                  

                HugoLidia wrote:
                Should my script read :

                If [IsEmpty(policies:: policyno) = 0 ]


                I would write it as:

                If [ not IsEmpty ( policies:: policyno ) ]

                I believe that's less error prone - and more readable to boot.

                 

                 

                 


                HugoLidia wrote:

                why one can't enter freehand text, to include comments in the script.


                First, you CAN (and should) - include comments in the script. There is a Comment[] script step (no affilliation :)) specifically designed for this purpose. You can also include comments in any calculation formula.



                The reason why Filemaker won't let you enter scripts in freehand is that you actually "write" only a very small part of the script's code. For example, you specify the field's name, but the script actually stores the field's ID - so that it will continue to function if the field is renamed.

                This way, non-technical folks can put together fairly complex scripts with practically no room for syntax errors - and that was (and to some extent still is) one of Filemaker's chief objectives.




                • 5. Re: Help needed to understand how to format script
                  HugoLidia
                    

                  Would appreciate ongoing help  - still can't get this to work.

                   

                  Trying to get the type of cover, held in field named "cover_type" checked so if it is blank the user is forced to go back and select a valid entry.

                   

                  Using Manage Database on the policies table, "cover_type" field I have the validation set as

                  Not Empty

                  Member of value List: CoverType ("TP", "TPF", etc etc.)

                  Validation by Calculation :   not IsEmpty(Self) and policy_type="Car", with the "validate only if foeld has been modified" deselected.

                  Display custom message : "Error - Type of Cover invalid.  Please select from the dropdown list"

                   

                  Also have text format set to UPPERECASE for this field.

                   

                   

                  So, when User enters "tp" it converts to "TP", or if I select a value from teh dropdown list I get the error message and have to revert the record?  As I do if the input is "xx", which is correct.

                   

                  Any ideas why a valid entry is being rejected?

                   

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

                   

                  Arrrg!!! Please ignore. Idiot here had field from original policies table on the tab control - should have been the TO field.  Now works.

                   

                  Thanks once again for all the input

                  • 6. Re: Help needed to understand how to format script
                    philmodjunk
                      

                    Perhaps because Policy_type does not equal "car"?

                     

                    I got a real kick out of this post because I can see it is the culmination of many different posts you made on various threads.

                     

                    Given the multiple layers of validation rules, I'd give serious consideration to removing some of them and adding a triggered script that checks for the removed validation issues. You only get one validation message from the validation field options where your script can be "smart enough" to identify distinctly different data entry errors and display different error messages specific to the error identified.

                    • 7. Re: Help needed to understand how to format script
                      HugoLidia
                        

                      Thanks PhilModJunk for your input and I would agree with you that a script is probably the best way to go.  But as a newbie to FM I need to build slowly ( and sometimes it must be painful for the likes of yourself to watch my efforts via my threads) and then once all running as I wish I can tidy up the code. 

                      By doing it this way it sinks in better - works for me anyway!

                      • 8. Re: Help needed to understand how to format script
                        comment_1
                          

                        Note:

                        Script triggers are NOT to be used as a replacement for field validation. If you want to ensure data integrity, use field validation first and foremost. Then, if you want, you may add a script trigger to bypass Filemaker's annoying validation error messages.

                         

                         

                        ---

                        That said, there is realy no need to validate the same thing twice - e.g. if you are validating not Is Empty ( Self ) by calculation, you don't need to check the 'Not empty' box, and vice versa.