5 Replies Latest reply on Dec 17, 2013 5:50 AM by MarkRuddeforth

    1st Script Help

    MarkRuddeforth

      Title

      1st Script Help

      Post

           Built my first script to change the value of a field based upon the existence of an entry in a date field - and of course it doesn't work......

           Go To Layout [ "CUSTOMERS" (CUSTOMERS) ]

           Go To Record/Request/Page [First]

           Loop

                If [ IsEmpty (CUSTOMERS::CONTRACTDATE) ]

                      Set Field [ CUSTOMERS::CONTRACT["E"] ]

                Else

                      Set Field [ CUSTOMERS::CONTRACT["X"] ]

                End If

                Go To Record/Request/Page [Next: Exit after last ]

           End Loop

            

           See anything obvious as to why it does nothing? Is there a way to print a message to the screen during a script execution - that would help me with debugging....

           Thanks,

           Mark

        • 1. Re: 1st Script Help
          SteveMartino

               Is that exactly how the script is written?  Try:

               Go To Layout [ "CUSTOMERS" (CUSTOMERS) ]
                
               Go To Record/Request/Page [First]
                
               Loop
                
                    If [ IsEmpty (CUSTOMERS::CONTRACTDATE) ]
                
                          Set Field [ CUSTOMERS::CONTRACT ; " E "]
                
                    Else
                
                          Set Field [ CUSTOMERS::CONTRACT ; " X " ]
                
                    End If
                
                    Go To Record/Request/Page [Next: Exit after last ]
                
               End Loop
                
          • 2. Re: 1st Script Help
            SteveMartino

                 I can't edit with iPad.  No " " 

            • 3. Re: 1st Script Help
              symbister

                   OK - rookie mistake but understandable

                   Set Field takes two arguments, the field that you're setting, and the value you are setting it to.

                   When you invoke Set Field, you'll notice two buttons in the bottom right corner, one for the field, (Specify Target Field), one for the value (Calculated Result - Specify)

                   Your target field is CUSTOMERS::CONTRACT - good, but your value needs to specified as a calculated result, in other words, when you click on Specify against Calculated Result, you're presented with a dialogue box to enter a calculation - in your case it will be "E" for your first Set Field.

                   Script step will then be

                   Set Field [CUSTOMERS::CONTRACT ; "E"]

                   and yes, if you use the script step 'Show Custom Dialog' near the bottom of the list under Miscellaneous, you can check what your values are doing, but better still, consider upgrading to Filemaker Pro Advanced, which includes a Script Debugger and Data Viewer..

              • 4. Re: 1st Script Help
                hbrendel

                     Consider to make CUSTOMERS::CONTRACT a calculation field with the formula:

                     Case ( IsEmpty ( CUSTOMERS::CONTRACTDATE ) ; "E" ; "X" )

                     No script to run, never to worry about it ever...

                • 5. Re: 1st Script Help
                  MarkRuddeforth

                       Many thanks for the replies. It's interesting to me (not in a good way) that my using the script manager to build the script produced the incorrect syntax

                       Set Field [ CUSTOMERS::CONTRACT["E"] ] when it should have been

                       Set Field [ CUSTOMERS::CONTRACT ; " E " ] as you guys have pointed out.

                       Turns out that when the Set Field dialog box opened, I entered my text value "E" in the Repetition field at the bottom. It seemed to take it just fine, but apparently produced a Set Field command that was to repeat "E" times.... hence the failure.

                       I really like this approach though " Case ( IsEmpty ( CUSTOMERS::CONTRACTDATE ) ; "E" ; "X" ) " - takes me back to my C programming days in college.... so many dead brain cells from here.....

                       Thanks again for the help!