11 Replies Latest reply on Apr 30, 2014 8:17 AM by erolst

    Confusion over Set Field By Name

      I have a simple field on a form where I can use SET FIELD fine to update the value, but trying to use SET FIELD BY NAME instead does not work (for me, yet).

       

      After looking at the examples in the help, I'm still mystified.

       

      This is a simple date field called CHECK_DATE and I want to write a script to update that field with the current date (Get(CurrentDate)).

       

      The SET FIELD does this fine, but the SET FIELD BY NAME has no effect (fails with the "102" - Field Not Found, error).

       

      In the SET FIELD BY NAME target field, I simply picked the field name from the list of fields (no "calculation" required).

       

      In the Calculated Result calculation, I have the expected: Get(CurrentDate).

       

      Yet, when I run the script, nothing happens (except for the 102 error, that is).

       

      ----

       

      I've also tried creating two variables and then using the "$" variable names for each part of the SET FIELD BY NAME, but no dice.

       

      Not sure why this is so confusing, but I'm clearly missing something.

       

      Would appreciate any insights on how to get SET FIELD BY NAME working.

       

      Thanks,

       

      -m

        • 1. Re: Confusion over Set Field By Name
          beverly

          do you have the "fully qualified" name of the field (i.e. including the table/table occurrence name) and not just the field name?

           

               table::field

           

          Beverly

          • 2. Re: Confusion over Set Field By Name
            erolst

            morkus wrote:

            In the SET FIELD BY NAME target field, I simply picked the field name from the list of fields (no "calculation" required).

             

            That's what you're missing: While Set Field expects a field name that you select as a hard-coded parameter from the existing field names, Set Field by Name expects for its targetv field argument an expression (a calculation, if you wish) that resolves to a field name.

             

            If e.g. your field name is "myFieldName", you could use a hard-coded string "myFieldName" (which by itself obviously wouldn't offer any advantage over Set Field), or a reference to a field or variable which in turn holds the text "myFieldName" – or the result of a calculation using any of the above.

             

            In your case, specifying a field names causes the Calculation Engine to use the contents of the specified field as the target field name – which obviously fails with “field not found”.

             

            You would use Set Field by Name if e.g. you wouldn't know beforehand which of several fields to write into, or if you wanted to distribute the contents of a list into several fields by looping through their names.

             

            Since in your case you know the target field, you could simply use Set Field.

            1 of 1 people found this helpful
            • 3. Re: Confusion over Set Field By Name
              datastride

              And think about using GetFieldName (Table::Field) to ensure the script keeps working if you change the name of this field.

               

               

               

              #end

               

              Peace, love & brown rice,

               

              Morgan Jones

               

               

               

              FileMaker + Web:  Design, Develop & Deploy

               

              Certifications: FileMaker 9, 10, 11 & 12

               

              Member: FileMaker Business Alliance

               

              One Part Harmony <http://www.onepartharmony.com/>  

               

              Austin, Texas • USA

               

              512-422-0611

              • 4. Re: Confusion over Set Field By Name

                Thanks so much Morgan and "erolst". Both of your suggestions worked great. I finally figured out how to use this script step!

                 

                 

                 

                -- m

                • 5. Re: Confusion over Set Field By Name
                  user22423

                  I have a related problem as Morkus but i can't find an explanation why my script don't work

                   

                  The context of the script is to transpose (like the transpose in Excel) from a source table to another target table by selecting the fieldnames on behalf of parameters. In the end the target table is used for an export to an Excel file.

                   

                  In the screen capture below (at the red arrows) you can see that I can use two options to fill the contents of Export_test::colname field in the target tabel. The Set Field scriptrule works but the Set Field by Name scriptrule doesn't. Finally it's my goal to make the attribute Export_test::colname a dynamic one. But that is now not the point.

                   

                  I tried a lot of combinations:

                   

                  - using or not of Fully Qualified Names

                  - use hard code values like "fieldcontent" or calculated values in the target attribute of Set Field by Name scriptstep

                  - using different relations of fields in tables

                   

                  What is going on here? Whay does this script don't work? I'm very confusing about his problem.

                   

                  A speedy response will be very appreciated.

                  Thanx in advance..

                   

                  Harold

                   

                   

                  My Script (partially)

                   

                  Script Set Field By Name.jpg

                   

                  • 6. Re: Confusion over Set Field By Name
                    erolst

                    Harold Ingen wrote:

                    Finally it's my goal to make the attribute Export_test::colname a dynamic one. But that is now not the point.

                     

                    I'm afraid that's very much the point, as was pointed (well …) out in the previous posts.

                     

                    Do you want to populate Export_test::colname, or do you want to populate the field that Export_test::colname references?

                     

                    If the former, then you can just use Set Field and select Export_test::colname as hardcoded argument; if the latter, make sure that Export_test::colname holds an expression that resolves to a fieldname.

                     

                    btw …

                     

                    1. You don't need to enter Find mode if you're performing a stored Find

                     

                    2. You can simplify and speed up your script by compiling, then processing a variable list and avoiding jumping back and fro between layouts:

                     

                    # on layout A

                    Loop

                      Set Variable ( $IDList ; List ( $IDList ; TableA:ID )

                      Go to Record [ Next ; Exit after last ]

                    End Loop

                    Go to Layout [ B ]

                    Loop

                      Exit Loop if [ Let $i = $i + 1 ; $i = ValueCount ( $IDList ) ) ]

                      New Record/Request

                      Set Field [ TableB::someField ; GetValue ( $IDList ; $i ) ]

                    End Loop

                     

                    … or consider simply using an Import [] of the found set in the search TO.

                    Harold Ingen wrote:

                    I'm very confusing about his problem.

                    Indeed …

                    • 7. Re: Confusion over Set Field By Name
                      user22423

                      Thanks for your support!  Those two tips I will take it in further coding but now I want to understand the scriptstep.

                       

                      Let me explain further:

                       

                      My goal is to find the colomn in the target table by a calulation. The name of the taget Fieldname is "colname". In this field I would like to fill the variable $DUP_Project_ID.

                       

                      Thus I want to populate a table with a value in a specified Field by a calculation. I tried the following expressions in the scriptrule:

                       

                      (both don't work)

                       

                      Set Field By Name ["colname"; $DUP_Project_ID]

                      Set Field By Name [$Colname; $DUP_Project_ID]  with previous scriptstep: Set Variable [$Colname; Value"colname"]   or other calculations

                       

                      I tried to resolve different calculations with other variables... nothing happens in the destination table with the field "colname". The table populates all records but the field "colname" stays empty.

                       

                      What is the core why I didn't understand why this is not working? My English is not optimal, maybe you have to make it more simple to me.

                       

                      THX,

                      Harold

                      • 8. Re: Confusion over Set Field By Name
                        erolst

                        Harold Ingen wrote:

                        I tried a lot of combinations:

                        - using or not of Fully Qualified Names

                        […]

                        Harold Ingen wrote:

                        Set Field By Name ["colname"; $DUP_Project_ID]

                        Set Field By Name [$Colname; $DUP_Project_ID]  with previous scriptstep: Set Variable [$Colname; Value"colname"]   or other calculations

                         

                        There's your problem: none of these expressions resolves to a fully qualified field name; it makes no difference if you use the field name directly as a literal or reference a variable.

                         

                        Try:

                        Set Variable [ $Colname; "colname" ]

                        Set Field By Name [ Get ( LayoutTableName ) & "::" & $Colname ; $DUP_Project_ID ]

                        • 9. Re: Confusion over Set Field By Name
                          user22423

                          A Truly Big THANKYOU !!!!

                           

                          That works finally. I was thinking in that direction but I was not shure. What is the reason, why do I have to resolve the FQN of the taget table? Has this scriptstep to be so explicit?

                           

                          But anyway. I can finish my export scenario's for now.

                           

                           

                          Thx,

                           

                          Harold

                          • 10. Re: Confusion over Set Field By Name
                            user22423

                            Type error ..

                             

                            Exit Loop if [ Let $i = $i + 1 ; $i = ValueCount ( $IDList ) ) ]      Should be:         Exit Loop if [ Let ( $i = $i + 1 ; $i = ValueCount ( $IDList ) ) ]

                             

                            Harold

                             

                             

                             

                                 

                            • 11. Re: Confusion over Set Field By Name
                              erolst

                              Harold van Ingen wrote:

                              Type error ..

                              Exit Loop if [ Let $i = $i + 1 ; $i = ValueCount ( $IDList ) ) ]      Should be:         Exit Loop if [ Let ( $i = $i + 1 ; $i = ValueCount ( $IDList ) ) ]

                              Harold

                               

                              Thanks, but this is a syntax error (happens when you type code from memory) which the Calculation Engine won't let go through anyway.

                               

                              You didn't spot the really serious – semantic – error I managed to put in; the step needs to read:

                               

                              Exit Loop if [ Let ( $i = $i + 1 ; $i > ValueCount ( $IDList ) ) ]

                               

                              or you don't process the last list item.