4 Replies Latest reply on Aug 3, 2011 11:42 AM by George99

    Use of GetField and GetFieldName

    George99

      Title

      Use of GetField and GetFieldName

      Post

      Hello all,

      Could anyone please tell me what I'm doing wrong?

      I have a layout with 5 fields, I need to run some verification scripts on the data in any one of the five fields before moving  onto the next step. Rather than write five separate verification scripts, I'm trying to write a generic script that can reference the fields by means of a variable.

      I thought getfield was the solution but it dosen't appear to work.

      What I'm doing is as I enter the field I set a variable to the  text name of the field then when I  leave the field, the data should be verified by a generic script.

      For example.

      On entry to the field

      SetVariable $$CurrentAnswer;Value"QuestionSheet::ScreenAnswer"

      Do I need to enter the table name or is that over kill?         

      ScreenAnswer being the name of the field with data to be verified. On attempting to leave the field the verification script runs.

       In the script I have the following line

      TrimAll ( GetFieldName (  $$CurrentAnswer ) ; 2 ; 3 ).

      (trimall is just part of a much bigger verification process).

      But no surprises, it dosen't work.

      Help please?.

      George Humphries Novice Filemaker user

      Using Filemaker pro 10 and windows XP.

        • 1. Re: Use of GetField and GetFieldName
          philmodjunk

          GetFieldName returns the name of a field.

          GetFieldName ( QuestionSheet::ScreenAnswer )

          and

          "QuestionSheet::ScreenAnswer"

          return the same identical results here

          GetFieldName ( "QuestionSheet::ScreenAnswer" )--don't think that will work and it's unecessary. Neither should you use Trim all in an attempt to remove spaces as any spaces in the field or table occurrence names are needed.

          I suggest this line for your first script:

          Set Variable [$$CurrentFieldName ; getFieldName ( QuestionSheet::ScreenAnswer ) ]

          Then, to access the data in this field use: GetField ($$CurrentFieldName ) to "read" the data and Set Field By Name [ $$CurrentFieldName ; //put calculation here] to modify it.

          The reason you'd use getFIeldName ( QuestionSheet::ScreenAnswer ) instead of just "QuestionSheet::ScreenAnswer" is that GetFieldName will automatically return the correct combination of table occurrence and field names should you change either of these two names where using text in quotes requires you to find and update that script step or script parameter expression.

          Oh yes, instead of assigning the value like this in a script--which puts you back to one script for each field, I'd pass the field name as a script parameter with the getFieldName expression so that a single script:

          Set Variable [$$CurentFieldName ; Value: get ( ScriptParameter ) ]

          will server for all such fields.

          • 2. Re: Use of GetField and GetFieldName
            George99

            At the end of your reply you suggest setting the variable what do you mean by (script parameter)?

            Sorry to be dense.

            George Humphries.

            • 3. Re: Use of GetField and GetFieldName
              philmodjunk

              When you use a script trigger, a button or the perform script step to perform a script, you can specify a script parameteter. Put the getFieldname expression inside the optional script parameter box.

              Then the get ( ScriptParameter ) function can be used to retreive the value passed to the script as the script parameter. This is a very useful way to set up diferent buttons that pass different data to the same script.

              • 4. Re: Use of GetField and GetFieldName
                George99

                Thanks I've nearly got it working now.

                I didn't appreciate that Getfield gathered the data in that particuler field.

                Also the need for the set field by name.

                It's not very clear in the help files.

                George Humphries.