12 Replies Latest reply on Mar 25, 2014 6:06 PM by SteveMartino

    Set Field by Name and the dreaded 102 error message

    RoelfWoldring

      Title

      Set Field by Name and the dreaded 102 error message

      Post

           I am getting a 102 error in a Set Field by Name script step which I don’t understand. After several hours of trying to get around it, I am finally looking for help.

            

           I will write it up in Word, then post it, attaching a JPEG which contains the various screen captures (script, debugger and data viewer)

            

           First here is the script.

            

           It is an OnObjectEnter script trigger script whose only purpose is to turn field contents to Yes if they are no and if another field has some content.

            

            

           Script debugger gives me a 102 error on the Set Field by Name Step

            

            

            

           Data viewer tells me the following

            

           see data viewer

            

           When I try using Set Field directly in the script on the same field as I am using in Set Field by name, it works with no problem.

            

           Searching around for a while on the forum, I tried eliminating the field that I am using in the Set Field by Name on the layout and re-establishing it. Same 102 results.

            

           So Given that I can use a Set Field to write into this field, and that I can get the field contents earlier in the same script, I am completely flummoxed.

            

           Help please

            

            

      102error.jpg

        • 1. Re: Set Field by Name and the dreaded 102 error message
          philmodjunk

               THe field name should not be enclosed in quotes. And what exact text is passed to your script as a script parameter?

               Set field by name expects text in this format for the first parameter:

               TableOccurrenceName::FieldName

               So often the problem is that the first part of the field reference is missing.

          • 2. Re: Set Field by Name and the dreaded 102 error message
            RoelfWoldring

                 Thanks

                 But this quote in the Filemaker 12  fucntion reference manual surely confuses me:

                 The Set Field By Name script step lets you create a calculation to specify a field name, then change the value of the field either literally or based on a second calculation.
                 The calculated target field must return a text result.
                 If quotation marks are not included around the fully qualified field name, the target field name is obtained from the named field.
                 If no field is specified and a field is selected in Browse mode or Find mode, that field is used.

                 I am not really sure about how to read this line and what it practially speaking means:

                 If quotation marks are not included around the fully qualified field name, the target field name is obtained from the named field.

                 I have tried doing it both ways - with and without enclosing quotes in the text level contents of the field name. I get same 102 error results.

                 I am really confused by the fact that earlier in this script I can use the $DocumentedFlagFieldName variable to get the field contents successfully (as evidenced by Data Viewer), ....

                 but that when I use the same variable name in the set field by name line, (with or without enclosing quotes), it tells me that the field is missing.

                 I tried creating a version of the script in which I used GetActiveTableName and GetActiveFieldName to create the name of the field which fires the OnObjectEnter Script trigger. Same 102 error results in the Set Field by Name script step.

                 The input line to this script, set in the OnScriptTrigger dialogue window is:

                 List

                 (
                 GetFieldName ( BD:ExecButtSTFields::DObjectName ) ;
                 GetFieldName ( BD:ExecButtSTFields::DObjectDocumentedFlag)
                 )

                 Data Viewer shows that these names are being passed to the script in fully qualified form, without enclosing quotes.

                 The idea is being that by using these field names as script input parameters, the script can be called from any one of a number of layouts with have the same functional dynamics.

                 I can just work around it by manually entering the field on each layout, but quite frankly, I am always intrigued by these sort of programming puzzles, expecially when their solution makes a user's life simplier and less error prone.

                  

                 Roelf

            • 3. Re: Set Field by Name and the dreaded 102 error message
              RoelfWoldring

                   Sorry but my last post is not an answer - hit the wrong button and there seems to be no easy way to undo it.

                   Have been thinking about this line in the documentation

                   If quotation marks are not included around the fully qualified field name, the target field name is obtained from the named field.

                   I think it means

                   if you enclose the name in quotes, then FM will treat what is in quotes as the field to be set - ie. what is in quotes is the field name - fully qualified.

                   if you do not enclose the name in quotes then FM will get the contents of the field or variable in this case, and use it as the fully qualified field name to set.

                   So if you use a variable to store the field name, make sure that is is not in quotes.

                   The fact that this script  step line works  (i.e. what you see in Data Viewer is exactly what you expect)

                   Set Variable ( $DocumentedFlagFieldContents; (GetField ( $DocumentedFlagFieldName ) )

                   while this one does not

                   Set Field By Name ( $DocumentedFlagFieldName ; "Yes" )

                   in the same script has got me completely confused

                   or am I just blind and missing the obvious?

                    

                   Roelf

                    

              • 4. Re: Set Field by Name and the dreaded 102 error message
                RoelfWoldring

                     Thought I would have one more careful read of the FM 12 Script Step document before letting this go for supper

                     Here is Example 5

                     Example 5
                     This example uses a field name contained in a variable to calculate temperatures. A user enters the temperature in field F or field C and runs the script in order to convert temperatures between Fahrenheit and Celsius.
                     If [Get (ActiveFieldName) = “F”]
                     #Convert Fahrenheit to Celsius
                     Set Variable [$TargetField; Value:”TableName::C”]
                     Set Field By Name [$TargetField; (5/9)*(Get (ActiveFieldContents)-32)]
                     Else if [Get (ActiveFieldName) = “C”
                     #Convert Celsius to Fahrenheit
                     Set Variable [$TargetField; Value:”TableName::F”]
                     Set Field By Name [$TargetField; (9/5)*Get (ActiveFieldContents)+32]

                     in this line of that example

                     Set Variable [$TargetField; Value:”TableName::C”]

                     the fully qualified name placed in the $TargetField variable is enclosed in quotes

                     because it is a "text field" that is being used to set a variable content value

                     in Data Viewer the value for $DocumentedFlagFieldName is BD:ExecButtSTFields::DObjectDocumentedFlag

                     so the script input work is clearly working.

                     Roelf

                • 5. Re: Set Field by Name and the dreaded 102 error message
                  RoelfWoldring

                       I have made one more effort to program around this

                       by creating a global field in a global field table that I have

                       and setting it to the field name of the field that I want to use in the Set Field by Name step

                       and then using this global field as the "go to field" in the the set field by name step

                       same 102 error

                       telling me that it is something about the field itself that is the problem I think

                       not the variable that I am using to set field by name step

                  • 6. Re: Set Field by Name and the dreaded 102 error message
                    philmodjunk

                         The quotes are needed only where you are setting the variable to a literal value. Quotes are used to tell FileMaker "take this next text exactly as I have typed it, don't try to evaluate it as the name of a variable or a field." Once you have assigned the text to a variable, and refer to the variable, you no longer need the quote characters.

                         You do not need to include the quotes themselves as characters in the variable that you are using in the first parameter of the set field by name step.

                         If you are passing the text for such a valid field reference to your script in the script parameter, then you should use:

                         Set Field By Name [ $DocumentedFlagFieldName ; "Yes" ]

                         This step

                         Set Field By Name [ $QuotedDocumentedFlagFieldName ; "Yes" ]

                         will fail because you have use Char to add characters (I am assuming the left and right quotation characters), to the beginning and end of the table::Field reference and thus no longer have a valid field reference.

                          

                    • 7. Re: Set Field by Name and the dreaded 102 error message
                      RoelfWoldring

                           CONTAINS WORKAROUND TO THIS SITUATION

                           SHOULD BE SET AS BEST ANSWER

                           (HOW DO WE CHANGE THAT SETTING ANYWAY????)

                            

                           So - on  with the problem solving

                           Step One

                           See if there is something wrong or corrupt with the definition of the target field in the original TO

                           so delete it

                           recreate it

                           update all the references to it on layouts in script trigger script calls in scripts

                           same result with using set field by name = 102 error

                           Step Two

                           Go back to documentation

                           read that if Set Field by Name does not have a target field it uses the current active field on the layout

                           Since Go To Field requires a selection out of the Fields dialogue

                           use Go to Object to go to variable name which contains target field name

                           change Set Field by Name to drop specify target field issue

                           same result 102 error in Debugger

                           Step Three

                           read documentation about Set Field

                           Set Field
                           Purpose
                           Replaces the entire contents of the specified field in the current record with the result of a calculation.
                           Format
                           Set Field [<table::field>; <value or formula>]
                           Options
                           •Select Specify target field or click Specify to specify the field whose contents you want to replace. If no field is specified and a field is selected in Browse mode or Find mode, that field is used.
                            

                           Keep Go To Object step

                           Replace Set Field by Name with Set Field step - no target field specified

                           result

                           no 102 error

                           target field updated properly

                           Conclusion

                           problem lies somewhere in FM Set Field by Name implementation Code

                           Since Go to Object & Set Field (do not specify target field) accomplish the same result

                           avoid Set Field by Name until FM looks into issue

                           THIS IS THE BEST ANSWER AND WORK AROUND

                           1 days progress lost

                           but something learned for the future

                           Roelf

                      • 8. Re: Set Field by Name and the dreaded 102 error message
                        philmodjunk

                             I've used set field by name extensively with no issues. Neither go to field nor go to object have any affect on set field or set field by name if they are set up to correctly reference a field in the first parameter.

                        • 9. Re: Set Field by Name and the dreaded 102 error message
                          RoelfWoldring

                               Thanks

                               will try it again in future

                               but for now the code works and does what it is supposed to

                               with no 102 error

                               I have used Set Field by Name in the past with a variable name with no issues

                               that is why I set up the code originally the way I did

                               it is only when it did not do what it has done in the past

                               that it started me down this path

                               but I had an issue here

                               probably something to do with this particular data base

                               maybe on this particular machine

                               I just wanted to get around it

                               and move forward

                               which I now have

                          • 10. Re: Set Field by Name and the dreaded 102 error message
                            SteveMartino

                                 To the original poster. I was wondering.....

                                 You posted this:

                            Set Variable ( $DocumentedFlagFieldContents; (GetField ( $DocumentedFlagFieldName ) )
                                  

                                 Should it be this?

                                 Set Variable ( $DocumentedFlagFieldContents; (GetFieldName ( $DocumentedFlagFieldName ) )
                                  
                                  
                            • 11. Re: Set Field by Name and the dreaded 102 error message
                              philmodjunk

                                   I did not post that.

                                   I posted:

                                   Set Field By Name [ $DocumentedFlagFieldName ; "Yes" ]

                                   As long as $DocumentedFlagFieldName has text in the format: Table::Field and "Table::Field" is the correct field reference for the current layout and current record context at the time that step executes, it should enter the text "yes" into the field specified in the variable.

                                   GetFieldName must have an actual field reference, not an expression in order to return a value-which will be text in exactly the correct format for Set Field by Name to use in the first parameter. GetField extracts the value of the field named in it's parameter. It's the functional opposite of Set Field By Name. (Set field by Name "writes" via indirect reference, GetField "reads" by indirect reference.)

                                   Often, when I use set field by name and/or getField in a script, I put GetFieldName ( Table::Field ) into the optional script parameter box in order to pass the correct text to my script to use in that script step and function. I do that so that if I later use Manage | Database to rename a table occurrence or a field, I won't break this script as GetFieldName will update to return the new text for that field reference.

                              • 12. Re: Set Field by Name and the dreaded 102 error message
                                SteveMartino

                                     Sorry Phil for not being specific.  The comment was directed at the OP.  I'll edit it.