1 2 3 Previous Next 32 Replies Latest reply on May 9, 2009 2:47 AM by mfwills_1

    Set Field By Name

    mfwills_1

      Title

      Set Field By Name

      Post

      [FMA 10.0v1 / OSX 10.4.11]

       

      Am I missing some trick to script step Set Field By Name?

       

      I am first setting the target field name in a Script Parameter.

       

      In the Set Field By Name step, I have tried it using Get(ScriptParameter) directly, by setting a Script Variable from the script parameter, even by setting a Global Field from the script parameter, both with and without the table name (Table::Field.

       

      The script hits the step, but does nothing to the value of the defined field.

       

      Matt

       

        • 1. Re: Set Field By Name
          mrvodka
            

          With Set Field by Name [], the field name that you want to reference should be a literal string or reference a field that has the fieldname as a value in it.

           

          So your script parameter value should be something like "Table::Field"

           

           

          *Edit

          P.S. Also, keep in mind that you could ( and perhaps should ) use GetFieldName to reference the field name so that in case the field name changes, your SetField by Name will not break.

          • 2. Re: Set Field By Name
            mfwills_1
              

            The idea was to set up a generic toggle script that takes the name of the field from the script param, so I don't have to write a separate script for every field I want to be able to toggle.

             

            In the following script, $Field, Get(ScriptParameter) and GetField ($Field) return the correct values, but Set Field By Name does nothing. I really don't see any difference between this and the examples given in Help:

             

            Set Variable [ $Field; Value:"Towns::" & Get(ScriptParameter) ]
            If [ GetField ( $Field ) = "Y" ]
            Set Field By Name [ $Field ; "N" ]
            Else
            Set Field By Name [ $Field ; "Y" ]
            End If


            • 3. Re: Set Field By Name
              mrvodka
                

              If you want one generic toggle script then you really should allow it for different tables as well.

               

              Here is what I would do.

              Script Parameter: GetFieldName ( Towns::toggle1 )

               

              Script:

              Set Variable [ $Field; Value:Get(ScriptParameter) ]
              If [ GetField ( $Field ) = "Y" ]
                Set Field By Name [ $Field ; "N" ]
              Else
                Set Field By Name [ $Field ; "Y" ]
              End If

               

               

              Now if you have another button, for a different table, all you have to do it change the parameter:

              Script Parameter: GetFieldName ( City::toggle3 )

               

               

               

              One additional thing. Normally when I use a toggle, I prefer a number boolean field. Its good for a number of things including generating reports, easy checkboxes, matches in relationships etc.

               

              If you do choose to use a number field instead of "Y" and "N". the script can simply be:

               

              Set Variable [ $Field; Value:Get(ScriptParameter) ]
              Set Field By Name [ $Field ; not GetField ( $Field )  ]

               



              • 4. Re: Set Field By Name
                mfwills_1
                  

                I am still getting nothing from the Set Field By Name step when I use a calculation.

                 

                If I use

                 

                Set Field By Name [ "Towns::FieldName"; "N" ], the step works.

                 

                If I set the script param to "Towns::FieldName", then use 

                 

                Set Field By Name [ Get(ScriptParameter) ; "N" ], it doesn't work.

                 

                What's the problem?

                 

                 

                • 5. Re: Set Field By Name
                  comment_1
                    

                  mfwills wrote: 

                  If I set the script param to "Towns::FieldName", then use 

                   

                  Set Field By Name [ Get(ScriptParameter) ; "N" ], it doesn't work.

                   

                  What's the problem?

                   


                  It looks like you are setting the parameter to the field's contents. You must use literal text (surrounded by quotes) to specify the field's name.

                  • 6. Re: Set Field By Name
                    philmodjunk
                      

                    comment wrote:
                    It looks like you are setting the parameter to the field's contents. You must use literal text (surrounded by quotes) to specify the field's name.

                    Not correct. I use Set Field By Name with expressions that evaluate to text and it works just fine.


                    • 7. Re: Set Field By Name
                      philmodjunk
                        

                      I'd either use script debugger (fmp advanced) or a show custom dialog step to check and see how Get(ScriptParameter) is evaluating. It may be that you are not getting the value you expect.

                       

                      I'd also check what I call "table context". Is this a field that is part of the current layout's table? If it's from a related table, is the relationship valid at the moment this script step is executed?

                      • 8. Re: Set Field By Name
                        mfwills_1
                          

                        I finally have it:

                         

                        Set Field By Name ( GetAsText ( Get ( ScriptParameter ) ) ; Value )

                        • 9. Re: Set Field By Name
                          mrvodka
                            

                          What was your REAL names for the table occurrence ( "Towns" ) and field ( "FieldName" )?

                           

                           

                          Also I really do think that you should incorporate the GetFieldName () function as I pointed out earlier...

                           

                          • 10. Re: Set Field By Name
                            D_J
                               The problem seems to be the contents of Get(ScriptParameter).  What are you passing as your parameter?
                            • 11. Re: Set Field By Name
                              mfwills_1
                                

                              mr_vodka wrote:

                              What was your REAL names for the table occurrence ( "Towns" ) and field ( "FieldName" )?

                               

                               

                              Also I really do think that you should incorporate the GetFieldName () function as I pointed out earlier...

                               


                              The actual field was Towns::SpanClassReplace. I used FieldName as a generic.

                               

                              I don't see how I could use GetFieldName. The name of the field I want to toggle is specified in the script parameter when I click the button. The field is not active.


                              • 12. Re: Set Field By Name
                                mfwills_1
                                  

                                D_J wrote:
                                The problem seems to be the contents of Get(ScriptParameter).  What are you passing as your parameter?

                                I described that in the original question: the script param is the name of the field I want to toggle.

                                 

                                Help describes referencing fields, calculations, etc. It does say "literal text," but does not suggest using GetAsText.


                                • 13. Re: Set Field By Name
                                  comment_1
                                    

                                  PhilModJunk wrote:

                                  comment wrote:
                                  It looks like you are setting the parameter to the field's contents. You must use literal text (surrounded by quotes) to specify the field's name.

                                  Not correct. I use Set Field By Name with expressions that evaluate to text and it works just fine.


                                  Nevertheless, what I wrote is correct. Of course you can use an expression that evaluates to text, instead of literal text (actually, literal text IS an expression that evaluates to text). The question is, what is IN the returned text. If your script parameter is:

                                   

                                  Table::Field

                                   

                                  it will return the CONTENTS of the field - which might be text. It might even be a valid field name - if that's what happens to be in the field. But if you want to pass the field's NAME, for use in the Set Field By Name[] step, your script parameter must be:

                                   

                                  "Table::Field"

                                   

                                  or an expression that returns the same, for example:

                                   

                                  GetFieldName ( Table::Field )



                                  • 14. Re: Set Field By Name
                                    comment_1
                                      

                                    mfwills wrote:

                                    Help describes referencing fields, calculations, etc. It does say "literal text," but does not suggest using GetAsText.


                                    That's correct. GetAsText() converts between data types, it doesn't change a reference. Therefore, it cannot be the answer to your issue, unless it's by some coincidence (or there's more to it than you have told us).


                                    1 2 3 Previous Next