Plug-ins > Address Book Manipulator

Use local variable within the PCAB_GetValueForUID function?


In my main contacts table I have address fields for up to 3 addresses per contact:

Address 1 UID
Address 1 Street
Address 1 City

Address 2 UID
Address 2 Street
Address 2 City

Address 3 UID
Address 3 Street
Address 3 City

I’m trying to write one loop that will go through each contact and all of their potential addresses by using a local variable that counts the iterations of the script.

I can’t figure out how to use The local variable within the PCAB_GetValueForUID for the field name area, so that it updates a different field with each iteration of the loop. The area in bold below is what I can’t get working.

Set Field By Name [“Contacts:: Address ” & $counter & “ Street”; PCAB_GetValueForUID( "Address" ; “Contacts::Address “ & $counter & “ UID” ; "Street" )]

Here’s a summary of what I’m trying to do with the script.:

--- Code: ---Set a Global field with PCAB_OpenFirstMVProperty(“Address”)
Set the local variable $counter to 1
Begin Loop
Exit Loop if global field has “!!Error” or “End” or $counter > 3 (Currently, I only need to have up to 3 addresses for each contact)

Set Field By Name [“Contacts:: Address ” & $counter & “ UID”; get UID from previously mentioned global field]
Set Field By Name [“Contacts:: Address ” & $counter & “ Street; PCAB_GetValueForUID(  "Address" ; “Contacts::Address “ & $counter & “ UID” ; "Street" )]
…Similar to above script step for the rest of the Address fields.

Add 1 to the $counter Variable
Set the Global field with PCAB_OpenNextMVPropter
End Loop
--- End code ---

I recognize that I could perform the same thing with multiple conditionals. However, I want to make it flexible so that I can easily increase the number of potential addresses if needed.

Again, thank you for your help—and please let me know if any clarification is needed.

Chris Turner:
Try wrapping the "Contacts::Address " & $counter & " UID" section within the PCAB_GetValueForUID function call with an "Evaluate" function.

See below:

Set Field By Name ["Contact::Address " & $counter & " Street"; PCAB_GetValueForUID( "Address" ; Evaluate( "Contacts::Address " & $counter & " UID") ; "Street" )]

Passing the quoted value of "Contacts::Address " & $counter & " UID" without the Evaluate statement will pass the literal string "Contacts::Address 1 UID" (if $counter = 1) as the UID to the PCAB_GetValueForUID function, which is not a valid UID. Using "Evaluate" will tell FileMaker to consider the statement "Contacts::Address 1 UID" as an expression (which it is, as it is a field expression), and return the value of that field (which is a valid UID for Address 1).

Chris, Thanks again. This worked flawlessly.


[0] Message Index

Go to full version