Plug-ins > Address Book Manipulator

Flexible number of multi value fields?

(1/1)

juskaiser:
I have contacts in my apple address book that I'm trying to pull into filemaker. Some of my contacts have 1 phone, for example, while others have up to 6. I'm trying to find a way make the number of email fields & phone fields be flexible. I don't want to have phone 16 as fields in all of my contacts, I only want that to shop in contacts that actually have 6 phone numbers. I'm using a separate table phone numbers and emails to provide the one to many relationship.

The issue that I'm running into is with the scripting for pulling the address book contacts. Do you have example scripts that loop through the fields that can have possibly more than one entry? The sample file only has conditional statements that go through two iterations, and again this isn't flexible.

Thanks for any help.

Chris Turner:
Hi juskaiser,

You should be able to use the functions "PCAB_OpenFirstMVProperty" and "PCAB_OpenNextMVProperty" within a looping scripting structure to achieve the task you're looking for.

The following sample script will show you how to iterate through an unknown number of Address multi-value properties for a contact:


--- Code: ---Set Variable [$result ; Value:PCAB_Open( $$ContactUID )]
If [ $result = "!!ERROR!!" ]
#
# Error handling...
#
End If
#
Set Variable [$uid ; Value:PCAB_OpenFirstMVProperty( "Address" )]
Loop
    #
    Exit Loop If [$uid = "!!ERROR!!" or $uid = "?" or $uid = "END"]
    #
    New Record/Request
    #
    Set Field [ Addresses::UID ; Value:$uid ]
    Set Field [ Addresses::Street ; Value:PCAB_GetValueForUID( "Address" ; $uid ; "Street" )]
    Set Field [ Addresses::City ; Value:PCAB_GetValueForUID( "Address" ; $uid ; "City" )]
    #
    # Pull all other fields in same manner...
    #
    Set Variable [$uid ; Value:PCAB_OpenNextMVProperty]
    #
End Loop
#
# Any other work...
#

--- End code ---

PCAB_OpenFirstMVProperty and PCAB_OpenNextMVProperty will return the UID of the multi-value property (of the type provided by PCAB_OpenFirstMVProperty), or the values "!!ERROR!!" or "END". To access the specific sub-properties (Street, City, State, etc.), use the optKey parameter in the PCAB_GetValueForUID function. When linking this to a record, you can set a foreign key in the Addresses table to equal the primary key of the original contact. The above example will loop through every attached Address defined for the contact with the UID $$ContactUID and create a new record for each instance in a table called "Addresses".

Thanks!

juskaiser:
Chris, I really appreciate the response. Thanks for your help.

I ended up figuring out, just about the same solution on my own. The other piece of the puzzle was creating the related records.  For this I used the "Magic Key" method found here: http://filemakerhacks.com/2011/07/31/magic-key-and-check-box-reporting/.

Navigation

[0] Message Index

Go to full version