1 Reply Latest reply on May 30, 2017 3:15 PM by erolst

    How to count the Get(FoundCount) in a loop of a script

    olivervollmer

      Hi,
      I don´t know how to solve this problem in my script:

      I have a ContactTable in listview Layout. I choose some Contacts and store the pk of these contacts in a global field of my contact table.

      Now i build a script, that goes to a new table and writes every PK from this virtuallist to a new record.
      Before i write new record, i proof with a perform find in a loop script if this PK is in the table. If not, a new record for this PK.

      So far so good....

       

      Now i want to count all PK that were not write as new records. I want to store this count in a variable.

      How can i solve this ? I am very happy about good tipps and techniques to get a best working solution. Thanks !!

       

      Here is my script:

       

      Set Variable [ $$pkFAV ; Value: CONTACTS::gSelectedContacts ]

      Go to Layout [ “FAVORITES_contacts” (FAVORITES_contacts) ]

      Show All Records

      Set Variable [ $list ; Value: CONTACTS::gSelectedContacts ]

      Set Variable [ $count ; Value: ValueCount ( $list ) ]

      Perform Find [Restore]

      Loop

        Set Variable [ $i ; Value: $i + 1 ]

        Set Variable [ $row ; Wert: HoleWert ( $list ; $i )  ]

        Constrain Found Set [Restore]

        If [ Get ( FoundCount ) = 0 ]

        Show All Records

        Go to Record/Request/Page [First]

        New Record/Request

        Set Field [ FAVORITES_contacts::pkCONTACTLIST ; $$pkFAV ]

        Set Field [ FAVORITES_contacts::pkCONTACT ; $row ]

        End (if)

        Exit loop if [ GetAsNumber ( $i ) ≥  GetAsNumber ( $count ) ]

      End Loop

        • 1. Re: How to count the Get(FoundCount) in a loop of a script
          erolst

          Try this:

           

          Set Variable [ $newList ; Value: CONTACTS::gSelectedContacts ]

          Set Variable [ $existingList ; ExecuteSQL ( " SELECT pkCONTACT FROM FAVORITES_contacts " ; "" ; "" ) ]

          Set Variable [ $newCount ; ValueCount ( $newList ) ]

          If [ ValueCount ( FilterValues ( $existingList ; $newList ) ) = $newCount ]

            Exit Script

          End if

          Go to Layout [ “FAVORITES_contacts” (FAVORITES_contacts) ]

          Loop

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

            Set Variable [ $currentNew ; GetValue ( $newList ; $i ) ]

            If [ IsEmpty ( FilterValues ( $currentNew ; $existingList ) ) ]

              write your stuff ; the contactID to write is in $currentNew ...

            End if

          End Loop

          There is maybe even a shorter way using some list logic that eludes me ATM.

           

          On the other hand, you could perform this check while selecting a contact as favourite. On the third hand, you could write those entries just in time ... and on a fourth hand, if all you need is the fact that a contact is in a list (no further (meta-)data), just store a list of IDs in a field and use a script to call them from the Contacts table.

           

          Some notes:

          - don't use $$ unless you need to. You will know when you need to.

          - there is no need to use GetAsNumber() with a loop counter. I've never seen anyone do it, snd never did it myself.

          - a table should - by definition - only have a single PK. All other keys are foreign keys.

          - no need to Show all Records before performing a search.