10 Replies Latest reply on Apr 23, 2012 2:00 PM by strngr12

    Go to next field not working.

    strngr12

      Hello,

       

      I have a script that iterates through the fields of a record using the following logic:

       

      Go to Layout

      Go to first field

      set variable $firstField as active field

      set variable $currentField as ""

      Loop

      if $firstField = $currentField exit loop

      set variable $currentField as active field

      do work on active field

      go to next field

      end loop

       

      But when I print out the results of "go to next field" it gives me the same result as the current field before that command. In other words, it doesn't seem to actually go to the next field but stays on teh same one instead and then. of course, exits the loop. Is there some dependency on fields that needs to be there for it to advance to the next one?

       

      Thanks,

       

      Dan

        • 1. Re: Go to next field not working.
          strngr12

          I actually figured this out, but need some other related help if anyone would be so kind.  It truns out that Go To Next Field goes in tab order.  If you reach a field in a layout that dead ends at a tab it appears you do not iterate to the next field even if there are more fieds.  Does anyone know a way around this?

           

          Thanks,

           

          Dan

          • 2. Re: Go to next field not working.
            raybaudi

            Try in this way:

             

            Go to Layout

            Go to first field

            set variable $firstField as active field

            Loop

            do work on active field

            go to next field

            exit loop if $firstField = active field

            end loop

            commit

            • 3. Re: Go to next field not working.
              raybaudi

              strngr12 ha scritto:

               

              it truns out that Go To Next Field goes in tab order.

              Yes, and if there aren't fields in the tab order, the script will stop at the first field.

               

              The solution ? Use a layout with all the needed fields staying in the tab order.

              • 4. Re: Go to next field not working.
                strngr12

                Thanks for your help.  Unfortunately I'm writting a script for a client file that I don't have any control over.  My loop works fine, I only have a problem getting to the next field if there's no tab to it.

                • 5. Re: Go to next field not working.
                  BruceRobertson

                  And of course - tab order or not - you cannot use the go next field script step to go to a calc field.

                  • 6. Re: Go to next field not working.
                    raybaudi

                    There is another way to do it, but not GOING to the field..., SETTING:

                     

                    Set error Capture [ On ]

                    Go to Layout [ "layout" ]

                    Set Variable [ $fieldNames ; Value:FieldNames ( Get ( FileName ) ; Get ( LayoutName ) ) ]

                    Loop

                    Set Field By Name [ Let( $i = $i + 1 ; Get ( LayoutTableName ) & "::" & GetValue ( $fieldNames ; $i ) ) ; " Your Calc Here" ]

                    Exit Loop If [ $i ≥ ValueCount ( $fieldNames ) ]

                    End Loop

                    • 7. Re: Go to next field not working.
                      strngr12

                      Thanks!  I can see how that is supposed tp work, but I can't get it to return anything.

                       

                      What I'm trying to do is turn a fieldname and value into:

                       

                      <attribute="fieldname">fieldvalue</attribute>

                       

                      And the append it to a document.  Do you know how I can do that using the above?

                       

                      Thanks again!

                      • 8. Re: Go to next field not working.
                        BruceHerbach

                        Hi,

                         

                        Start with the beginning of Raybaudi's script. 

                         

                        Go to Layout [ “Util - View as List Contacts” (Contacts) ] Set Variable [ $fieldnames; Value:FieldNames ( Get ( FileName ); Get ( LayoutName ) ) ] Set Variable [ $$document; Value:"" ] Set Variable [ $loopend; Value:ValueCount($fieldnames) ] Set Variable [ $cnt; Value:1 ] Loop

                        Set Variable [ $field; Value:GetValue($fieldnames;$cnt) ]

                        Set Variable [ $value; Value:GetField($field) ]

                        Set Variable [ $$document; Value:Let( $txt = "<attribute=" & $field & ">" & $value & "<attribute>";   List($$document; $txt)) ]

                        Exit Loop If [ Let( $cnt = $cnt + 1; $cnt > $loopend ) ]

                        End Loop

                         

                        When the loop completes the global variable will have a complete list of fieldnames and values. 

                        This part of the set variable for $$document builds the string you need. 

                        $txt = "<attribute=" & $field & ">" & $value & "<attribute>"

                         

                        You will have to play with this a bit to properly put in the " characters.

                        You can set up a layout to display the $$document as a merge variable and print it to a pdf or copy and paste.

                         

                        HTH

                        Bruce

                        • 9. Re: Go to next field not working.
                          BruceHerbach

                          Your format looks very similar to xml,   could you set up a style sheet and just export the data directly as xml?

                           

                          HTH

                          Bruce

                          • 10. Re: Go to next field not working.
                            strngr12

                            Thanks so much!