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 ]
Go to Layout [ “FAVORITES_contacts” (FAVORITES_contacts) ]
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 ...
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.
- 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.