11 Replies Latest reply on Nov 18, 2010 12:05 PM by Frinholp

    Go To Field using a variable

    Frinholp

      Title

      Go To Field using a variable

      Post

      Hi All

      I have a script where the field address is passed in as a parameter.

      To my dismay the Go To Field script step does not allow you to pass in a variable, rather an absolute address only.

      Anybody know of any work around to this?

      Thanks in advance

      Lee

        • 1. Re: Go To Field using a variable
          philmodjunk

          It can be a bit cumbersome to do this but it can be done:

          If [$Variable = "FeldName1"]
             Go To Field [YourTable::FieldName1]
          Else If [$Variable = "FieldName2"]
             Go To Field [YourTable::FieldName2]

          and so forth.

          • 2. Re: Go To Field using a variable
            raybaudi

            Why not something like:

            Loop
            Exit Loop If [ $var = Get ( ActiveFieldName ) ]
            Go to Next Field
            End Loop

            • 3. Re: Go To Field using a variable
              philmodjunk

              Works also, though I might choose to add an extra test to exit the loop if $var doesn't equal the name of any field on the layout so I don't get an infinite loop. Wink

              • 4. Re: Go To Field using a variable
                raybaudi

                Yes, and before the Loop:

                If [ ValueCount ( FilterValues ( $var ; FieldNames ( Get ( FileName ) ; Get ( LayoutName ) ) ) ) ]
                Loop
                Exit Loop If [ $var = Get ( ActiveFieldName ) ]
                Go to Next Field
                End Loop
                End If

                • 5. Re: Go To Field using a variable
                  Frinholp

                  Cheers Phil

                  Not really the perfect solution I was hoping for, but if that is the way it is, that's what it will have to be.

                  On slightly different note, I have fields from related tables on a layout. In my example these are fields from a related address table.

                  I would like to also use Go To Field to leave the cursor in one of the address fields when the script exits under certain conditions.

                  I have tried to use Go To Field but this does not seem to make the referenced field active.

                  I have many layouts in which I would like to re-use this script and therefore was hoping that I wouldn't have to use Go To Object as there would be many unique object names that I would have to create, and doing so would also render my 're-usable script' not as generic.

                  Could anybody offer their thoughts?

                  Thanks again

                  Lee

                  Edit: Sorry hadn't read the previous three posts. Ignore the following comment.

                  Not really the perfect solution I was hoping for, but if that is the way it is, that's what it will have to be. - Please Ignore

                  If [ ValueCount ( FilterValues ( $var ; FieldNames ( Get ( FileName ) ; Get ( LayoutName ) ) ) ) ]
                  Loop
                  Exit Loop If [ $var = Get ( ActiveFieldName ) ]
                  Go to Next Field
                  End Loop
                  End If

                  Nice solution, I like that. Genius!

                  • 6. Re: Go To Field using a variable
                    philmodjunk

                    Actually, I had forgotten about Go To Object. For many situations, that enables the needed level of indirection so you can go straight to the field without If statements or loops that step through the tab order until the cursor lands on the right field.

                    Go To Field should allow you to put the cursor in any field on your layout whether "local" or related.

                    There are two exceptions that I know of:

                    1. You can't ever see the cursor in a container field.
                    2. A related record must exist before you can see the cursor in the related field unless you have enabled "allow creation of records via this relationship" for the related field's table.
                    • 7. Re: Go To Field using a variable
                      Frinholp

                      I have decided to go with the looping option so that I don't have to name objects before they can be used in my script.

                      This presents another problem. Now I am unable to Set Field By Name as I am required to give the fully qualified address as the target. I know that I could simply use Set Field but that is assuming that the loop stated above gets initialised and finds the correct target field (could be two fields from related tables on the layout with same name?).

                      Is there a way that I can enter the fully qualified address as the script parameter and then extract the field name from it to compare to to the returned list of field names from 'FieldNames'.

                      Basically I need to convert the fully qualified address into a string, substitute '::' with a space and use RightWords.

                      It is the conversion from fully qualified address to string containing fully qualified address that I am struggling with.

                      Any help appreciated

                      Lee

                      • 8. Re: Go To Field using a variable
                        philmodjunk

                        You can use Get ( LayoutTableName ) in your expressions if all your referenced fields are local to the layout's table. (Not from a related table.)

                        BTW, this is looking a bit strange. You don't have to actually put the cursor in the field before you use Set FieldbyName to modifiy its contents. Just wondering why you are doing both here.

                        • 9. Re: Go To Field using a variable
                          Frinholp

                          The script in question here is a validation script. I have been asked to return the cursor to the field in which validation fails.

                          I have also been asked to automate the correcting of the validation error by the click of a button within the dialog. 

                          As an example 'This field has been entered in uppercase. What would like to do to proceed?' Ignore, Change Auto-format.

                          Auto-format would title case.

                          That is quite a rational request ........... some of the requests get more extremeYell

                          Hope that explains my predicament Phil

                          In response to your solution, unfortunately I have related fields.

                          Cheers

                          Lee  

                            

                          • 10. Re: Go To Field using a variable
                            philmodjunk

                            Yet you are able to set the field name in a variable. At the time this variable is set, you should also be able to capture the full name of the variable. GetFieldName is a possible function you can use here. It will return both the field and table occurrence names. Get ( ActiveFieldTableName ) is another possibility.

                            • 11. Re: Go To Field using a variable
                              Frinholp

                              Cheers Phil

                              I managed to set the field by name by using GetFieldName ( Evaluate ( $field ) ) to obtain the field reference.