Author Topic: Use local variable within the PCAB_GetValueForUID function?  (Read 1577 times)

juskaiser

  • Member
  • *
  • Posts: 8
Use local variable within the PCAB_GetValueForUID function?
« on: September 17, 2014, 05:28:36 AM »
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
etc…

Address 2 UID
Address 2 Street
Address 2 City
etc…

Address 3 UID
Address 3 Street
Address 3 City
etc…

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: [Select]
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

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

  • Administrator
  • Member
  • *****
  • Posts: 28
    • Productive Computing, Inc.
Re: Use local variable within the PCAB_GetValueForUID function?
« Reply #1 on: September 17, 2014, 08:18:23 AM »
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 Turner
Product Support Specialist
Productive Computing, Inc.

juskaiser

  • Member
  • *
  • Posts: 8
Re: Use local variable within the PCAB_GetValueForUID function?
« Reply #2 on: September 18, 2014, 10:39:21 AM »
Chris, Thanks again. This worked flawlessly.