1 2 Previous Next 22 Replies Latest reply on Mar 8, 2016 8:35 AM by sreese

    Set field not working in script

    rado

      I have tried 3 hours worth of things to get this to work and cannot figure our why this script will not clear my field.  The Project::Project Number Find Field will not clear when I enter a project number that is not found but choose not to create a new record by choosing cancel in the Show custom dialog box.  I should mention also that when it goes back to the Home Screen - Easy Find" layout the field is highlighted and everything selected but it takes pressing delete 2x before it will delete anything.

       

      Home Screen Find Script

      Copy [ PROJECTS::PROJECT NUMBER FIND FIELD ]

      [ Select ]

      Go to Layout [ “PROJECTS” (PROJECTS) ]

      View As

      [ View as Form ]

      Enter Find Mode [ ]

      Paste [ PROJECTS::PROJECT NUMBER ]

      [ Select ]

      Set Error Capture [ On ]

      Perform Find [ ]

      Set Field [ PROJECTS::Error Capture ; Get(LastError) ]

      If [ PROJECTS::Error Capture <> 0 ]

      Show Custom Dialog [ Title: "JOB NUMBER NOT FOUND"; Message: "PROJECT NUMBER NOT FOUND. WOULD YOU LIKE

      TO CREATE A NEW RECORD?"; Default Button: “OK”, Commit: “Yes” ; Button 2: “CANCEL” , Commit: “No” ]

      If [ Get(LastMessageChoice) = 1 ]

      New Record/Request

      Paste [ PROJECTS::PROJECT NUMBER ]

      [ Select; No style ]

      Go to Field [ PROJECTS::PROJECT NAME ]

      Show All Records

      Exit Script [ ]

      Else

      Perform Script [ “CANCEL” ]

      End If

      End If

      Show All Records

       

      CANCEL Script

      Go to Layout [ “HOME SCREEN - EASY FIND” (PROJECTS) ]

      Set Field [ PROJECTS::PROJECT NUMBER FIND FIELD ; "" ]

      Show All Records

        • 1. Re: Set field not working in script
          BruceRobertson

          First. Don't use copy/paste in scripts. Learn to use variables and set field.

          Seems your script should look more like this:

           

          Home Screen Find Script

          Set Variable[ $projectNumber;  PROJECTS::PROJECT NUMBER FIND FIELD ]

          Go to Layout [ “PROJECTS” (PROJECTS) ]

          View As [ View as Form ]

          Enter Find Mode [ ]

          Set Field [ PROJECTS::PROJECT NUMBER  ; $projectNumber ]

          Set Error Capture [ On ]

          Perform Find [ ]

          Set Field [ PROJECTS::Error Capture ; Get(LastError) ]

           

          If [ PROJECTS::Error Capture <> 0 ]

          Show Custom Dialog [ Title: "JOB NUMBER NOT FOUND"; Message: "PROJECT NUMBER NOT FOUND. WOULD YOU LIKE

          TO CREATE A NEW RECORD?"; Default Button: “OK”, Commit: “Yes” ; Button 2: “CANCEL” , Commit: “No” ]

            If [ Get(LastMessageChoice) = 1 ]

              New Record/Request

              Set Field [ PROJECTS::PROJECT NUMBER  ; $projectNumber ]

              Go to Field [ PROJECTS::PROJECT NAME ]

              Exit Script [ ]

            Else

              Perform Script [ “CANCEL” ]

            End If

          End If

           

          CANCEL Script

          Go to Layout [ “HOME SCREEN - EASY FIND” (PROJECTS) ]

          Set Field [ PROJECTS::PROJECT NUMBER FIND FIELD ; "" ]

          Show All Records

          • 2. Re: Set field not working in script
            sreese

            Greetings Rado,

             

            Let me see if I can be of some assistance:

             

            A couple of things:

             

            If you do not have FileMaker Pro advanced you can insert pauses in your script steps to ensure what you think is happening is actually happening.

             

            Start out with using set variable instead of copy. The biggest reason to do this is ease of trouble shooting.  For example:

             

             

            # Turn on error capture 
            
            Set Error Capture [on]
            
            Freeze Window
            
            # Get the search criteria
            Set Variable [ $findvalue ; Projects::Find_Field ]
            
            
            # Perform the find
            Go to Layout [ "Projects" (Projects) ]
            Enter find mode [ ]
            Set Field [ Projects::Project_number ; $findvalue ]
            Perform Find []
            
            # Check for errors
            Set Variable [ $lastError : "Get ( LastError) " ]
            if [ $lastError = 400 ]
            
                 # No search criteria entered
            
                 Go to layout [ original layout ]
            
                 Show Custom Dialog [ Title : "Error" ; Message: "Please enter search criteria" ; Default button: "OK" ]
            
                 Perform Script [ "Cancel" ]
            
                 Exit Script []
            
            
            Else IF [ Get (LastError) = 401 ]
            
                 # No search results found
            
                 Show Custom Dialog [ Title: "JOB NUMBER NOT FOUND"; Message: "PROJECT NUMBER NOT FOUND. WOULD YOU LIKE TO CREATE A NEW RECORD?"; Default Button: “OK”, Commit: “Yes” ; Button 2: “CANCEL” , Commit: “No” ]
            
            
                 # Check for user input
            
                 If [ Get( LastMessageChoice) = 1 ]
            
                      # Create a new job record
            
                      New Record Request
            
                      Set Field [ Projects::ProjectNumber ; $findvalue ] 
                      Go To Layout [ New Project Entry ]
                      Exit Script []
            
                 Else If [ Get ( LastMessageChoice = 2 ]
            
                      # Cancel
                      Perform Script [ Cancel ]
                      Exit Script []
                 End if
            
            
            Else if [ $lastError = 0 ]
            
                 # Everything was good to go
            
                 # Do stuff here
                 Exit Script []
            
            End If
            
            # Some other error occurred
            Perform Script [ "Send error to manager" ; $lastError ]
            
            # Return user to where they were originally
            
            Perform Script [ "Cancel" ]
            

             

             

            This script will ensure a few things happen

             

            •     A user fills out the search field
              • If it is not filled out it will show them an error
            •     If results were not found then it will do the following
              • Show a custom dialog allowing them to create the job
              • If they do not create the job it will take them back to their initial screen
            • If results were found it will do whatever you tell it to do
            • If there was some error besides the two you would expect send an error to the manager
            • 3. Re: Set field not working in script
              sreese

              Also why are you performing a find and showing all records? Are you just trying to get to the item in the list? I didn't know the purpose so I didn't put it in.

              • 4. Re: Set field not working in script
                rado

                Ok.  I used a variable instead of copy/paste.  Definitely easier to use but still getting same issue.

                • 5. Re: Set field not working in script
                  rado

                  Just left over from evolution of script I think.  I have deleted also. 

                  • 6. Re: Set field not working in script
                    rado

                    I am getting an error of 0 everytime.  Script works great but still doesn't clear the find field after cancelling creation of new record. 

                    • 7. Re: Set field not working in script
                      BruceRobertson

                      "I am getting an error of 0 everytime."

                      In other words; it is working correctly.

                      • 8. Re: Set field not working in script
                        BruceRobertson

                        Also; you're not showing us you current script. We know what has been suggested; but we don't know what you actually did.

                        • 9. Re: Set field not working in script
                          rado

                          As far as error goes it says it is working correctly and everything appears to be with the exception of the clearing the Proj Num find field when a match is not found but no new record is created (i.e. Cancel is selected from custom dialog box).

                           

                          Current script

                           

                          Home Screen Find

                          Set Error Capture [ On ]

                          Set Variable [ $ProjNum; Value:PROJECTS::PROJECT NUMBER FIND FIELD ]

                          Go to Layout [ “PROJECTS” (PROJECTS) ]

                          View As

                          [ View as Form ]

                          Enter Find Mode [ ]

                          Set Field [ PROJECTS::PROJECT NUMBER ; $projnum ]

                          Perform Find [ ]

                          Set Variable [ $lasterror ; Value:Get(LastError) ]

                          Set Field [ PROJECTS::Last Error ; $lasterror ]

                          If [ $lasterror = 400 ]

                          Go to Layout [ “HOME SCREEN - EASY FIND” (PROJECTS) ]

                          Show Custom Dialog [ Title: "ERROR"; Message: "Please enter search criteria"; Default Button: “OK”, Commit: “No” ]

                          Perform Script [ “CANCEL” ]

                          Exit Script [ ]

                          Else If [ $lasterror = 401 ]

                          Show Custom Dialog [ Title: "JOB NUMBER NOT FOUND"; Message: "PROJECT NUMBER NOT FOUND. WOULD YOU LIKE

                          TO CREATE A NEW RECORD?"; Default Button: “OK”, Commit: “Yes” ; Button 2: “CANCEL” , Commit: “No” ]

                          If [ Get(LastMessageChoice) = 1 ]

                          New Record/Request

                          Set Field [ PROJECTS::PROJECT NUMBER ; $projnum ]

                          Go to Field [ PROJECTS::PROJECT NAME ]

                          Exit Script [ ]

                          Else If [ Get (LastMessageChoice) = 2 ]

                          Perform Script [ “CANCEL” ]

                          Exit Script [ ]

                          End If

                          Else If [ $lasterror = 0 ]

                          Go to Field [ PROJECTS::NOTES 1 ]

                          Exit Script [ ]

                          End If

                          Perform Script [ “CANCEL” ]

                          • 10. Re: Set field not working in script
                            BruceRobertson

                            Do you have FileMaker Pro Advanced? Do you know how to step through the script with the debugger?

                            If you don't have advanced - this is precisely why the debugger feature is so useful.

                            • 11. Re: Set field not working in script
                              BruceRobertson

                              Is PROJECTS::PROJECT NUMBER FIND FIELD a global field?

                              It should be.

                              If the field truly is a global field, then setting it at any time should be OK.

                              But if not - and your CANCEL script is unmodified from what you wrote previously,  note what your script does:

                               

                              Go to Layout [ “HOME SCREEN - EASY FIND” (PROJECTS) ]

                              #found set is still zero

                              Set Field [ PROJECTS::PROJECT NUMBER FIND FIELD ; "" ]

                              #found set is still zero - so above only worked if field is a global field

                              Show All Records

                              #now we are probably on a different record

                              • 12. Re: Set field not working in script
                                Stephen Huston

                                Why bother setting a field to the last error? Just run a test for

                                Get(FoundCount)=0

                                to branch to the appropriate action.

                                • 13. Re: Set field not working in script
                                  taylorsharpe

                                  Probably some of the other advice above is the answer, but I thought if you would check and make sure the field is not a calc field or if it is an input field (date/number/text), that the field does not have the "Prohibit modification of value during data entry" checked in the field definition. 

                                  • 14. Re: Set field not working in script
                                    Vaughan

                                    Two things:

                                     

                                    1) Only a global field can be set in Find mode. So unless the PROJECTS::Error Capture field is global your method of capturing the error will fail.

                                     

                                    2) You need to capture the error from the Perform Find step, not the Enter Find Mode step.

                                     

                                    Global fields were used pre-8.5 (IIRC) before variables were introduced. As others have said, use a script variable to capture the error.

                                    1 2 Previous Next