6 Replies Latest reply on Feb 6, 2009 2:07 PM by Orlando

    Script Advice

    carlz_1

      Title

      Script Advice

      Post

      Hi everyone.  Still a Newbie.  Can anyone give me scripting advice.  Below is a script I designed that is faulty.  I am trying to design a script that will start with the first field in a single record and look for fields that contain no data.  Here is what I've come up with so far.

       

      Omit Record

      Show Omitted Only

      Go to Layout ("Resident" (RESIDENT)

      Go to Field (RESIDENT:: name_last)

      Go to Next Field

      Loop

      If(GET(ActiveFieldContents)="")

      Halt Script

      Else

      Go to Record/Request/Page[Next; Exit after Last]

      EndIf

      End Loop

        • 1. Re: Script Advice
          Orlando
            

          Hi there carlz

           

          To fix the script you have so you loop through the fields on a layout and stop whne you reach an empty field try this:

           

          #
          # Isolate the current record   
          Show All Records 
          Omit Record 
          Show Omitted Only 
          # 
          # Go to the first field in your tab order  
          Go to Field [ TABLE::First Field Name ] 
          Loop 
          # Check if currently active field has a value
          If [ IsEmpty ( Get ( ActiveFieldContents ) ) ] 
          # Field is empty so stop script  
          Halt Script 

          Else   
          Go to Next Field 
          End If 
          # Specify the name of the last field in you tab order so the script does not loop round again

          Exit Loop If [ Get ( ActiveFieldName ) = "Last Field Name" ] 
          #  
          End Loop    

          Do you want the check to stop when you reach an empty field, or would you want to present a list of empty fields to the user.

           

          There are also other ways you can highlight empty fields using Conditional formatting that might be worth a try, depending on how you want the result presented to the user.

           

          let me know if this helps or not.





          • 2. Re: Script Advice
            carlz_1
              

            THANK YOU!  THAT WORKED.

             

            ONE LAST QUESTION ON THIS?  WHAT IF, INSTEAD OF HALTING THE SCRIPT I WANTED THE SCRIPT TO PAUSE, ALLOW THE USER TO ENTER DATA IN THAT PARTICULAR FIELD, AND THEN CONTINUE THE SCRIPT UNTIL THE END OF THE RECORD WAS REACHED? 

             

            MANY THANKS. 

            • 3. Re: Script Advice
              Orlando
                 Which version of FileMaker are you running this on???
              • 4. Re: Script Advice
                carlz_1
                  

                Pro Advanced 9 

                 

                 

                • 5. Re: Script Advice
                  carlz_1
                    

                  Orlando,

                   

                  One other question, can you show me script that would resent only the unanswered or empty fields as you referenced in your post?

                  • 6. Re: Script Advice
                    Orlando
                      
                    Since you have FileMaker 9 you can use Conditional Formatting and a Global Variable to highlight fields or labels that are blank after the script has been triggered. 
                     
                    You have two options here, one is to change the colour of the label to highlight that the field needs completing, the other is the highlight the field itself, I will go through both and you can choose which one you prefer.
                     
                    The trick here is to use a Global Variable as part of the Conditional Formatting so the field of label is not always highlighted, but only after the script has run.
                     
                    Lets start with the Conditional Formatting. If you have not used Conditional FOrmatting before all you need to do is, in Layout Mode, highlight the field or label you want to apply the conditional formatting to and go: Format > Conditional...
                     
                    Then a dialog will appear for you to input the Condition and the Format for that object.
                     
                    If you are ighlighting the actual field you can highlight all of the fields and apply the same calculation as we will use the Self function in order to reference itself to see if it is empty, however if you are doing the label you will need to do each individually as you need to reference the field in the calculation.
                     
                    Click on the 'Add' button to create a new Condition and
                     
                    For the Field Highlight input the following as the Condition:
                     
                    $$Check = 1 and IsEmpty ( Self ) 
                     
                    And then for the Format, make the 'Fill Color:' Red.
                     
                    If you are doing the labels then the condition will need to be:
                     
                    $$Check = 1 and IsEmpty ( TABEL::Field ) 
                     
                    And then for the Format, make the 'Text Color:' Red. 
                     
                    Once this is done click 'OK'
                     
                    After all of the formatting is done you need to amend you script to halt when an empty field is found, but first set the $$Check variable to 1, and if/when all fields are complete, clear the variable.
                     
                    So your script will look like this: 
                     

                    Show All Records 
                    Omit Record 
                    Show Omitted Only 

                    Go to Field [ TABEL::Field1 ] 

                    Loop 
                    If [ IsEmpty ( Get ( ActiveFieldContents ) ) ] 

                    Set Variable [ $$Check ; 1 ] 
                    Show Custom Dialog [ Title: "Message" ; Message: "Some information is missing. Please complete before continuing." ]
                    Halt Script 


                    End If 

                    Exit Loop If [ Get ( ActiveFieldName ) = "field4" ] 

                    Go to Next Field 


                    End Loop 


                    Set Variable [ $$Check ; "" ] 
                    #  
                     
                    This will then alert the user there is a field missing and exit the script, presenting them with highlights to show them which fields they need to complete before they can complete the record. 
                     
                    An alternative to this script to do the same thing, but without the loop and giving you more control over the fields checked is to have and If step and use the IsEmpty ( Field ) or IsEmpty...
                     
                    Show All Records 
                    Omit Record 
                    Show Omitted Only 
                    # 
                    Go to Field [ TABEL::Field1 ] 
                    # 
                    If [ IsEmpty ( TABEL::Field1 ) or IsEmpty ( TABEL::Field2 ) or IsEmpty ( TABEL::Field3 ) or IsEmpty ( TABEL::Filed4 ) ] 
                    # 
                    Set Variable [ $$Check; Value:1 ] 
                    Show Custom Dialog [ Title: "Message"; Message: "Some information is missing. Please complete before continuing."; 
                    Buttons: “OK” ] 
                    Halt Script 
                    # 

                    End If 
                    # 
                    Set Variable [ $$Check; Value:"" ] 
                    # 
                     

                    Worth a though as it may make it easier to maintain.

                     

                    I have put both of the Label and Field highlight options together in a demo to help you along, along with all the script examples and you can download if here:

                     

                    http://dl.getdropbox.com/u/552420/FileMakerForumDemos/carlzEmptyFieldDemo.fp7

                     

                    I hope something here helps you out.