6 Replies Latest reply on Feb 18, 2013 8:47 AM by philmodjunk

    Swapping address fields

    NigelBooth

      Title

      Swapping address fields

      Post

           Hi i am new to filemaker pro.

           I have 2 address fields ie shipping and billing

           I would like to create a button that will swap the data in these fields over so that the billing address becomes the shipping and vice versa. Can someone please help me on how this script would be written.

           Thanks for your help

        • 1. Re: Swapping address fields
          philmodjunk

               The standard "swap" alogrithm used throughout many different programming languages can be used:

               To swap values between field1 and field2:

               Set Variable [$Temp ; Value: YourTable::Field1]
               Set Field [YourTable::field1 ; YourTable::Field2]
               Set Field [YourTable::field2 ; $Temp ]

               That can be extended to "swap" between multiple address fields, but if you put these addresses in separate related records, all you need "swap" are the values in the match fields that link your current record to shipping and billing address records.

          • 2. Re: Swapping address fields
            NigelBooth

                 Thanks i will give that a go.

            • 3. Re: Swapping address fields
              NigelBooth

                   I tried this and it does as you said but it does cause me another problem.

                   It swaps the address on all orders not just the order i am in any ideas?

              • 4. Re: Swapping address fields
                philmodjunk

                     Sounds like you are swapping data in the contacts record instead of the order record. If you swapped data in the order record, the other records would remain unmodified.

                • 5. Re: Swapping address fields
                  NigelBooth

                       This is the script i have used 

                       Set Variable [ $Temp; Value:order_ADDRESS_pickup::__kp_addressID]

                       Set Field [order_ADDRESS_pickup::__kp_addressID; order_ADDRESS_destination::__kp_addressID]

                       Set Field [order_ADDRESS_destination::__kp_addressID; $Temp]

                       This script changes all instances of an address used on all orders have i done something wrong or do i need to find another way to do this.

                       Thanks for your help

                       Nigel

                  • 6. Re: Swapping address fields
                    philmodjunk

                         It looks like you have relationships that are not set up to make the "swap" work like you want. You are not modifying values in Orders, but in the related tables and thus the change appears for all Orders records.

                         You would need these relationships:

                         Address_pickup-----<Orders>-----Address_Destination

                         Address_pickup::__pkAddressID = Orders::_fkAddressPUID
                         Address_Destination::__pkAccressID = Orders::_fkAddressDestID

                         Set Variable [ $Temp ; Value: orders::__kp_addressPUID]
                         Set Field [orders::__kp_addressPUID ; Orders::_fkAddressDestID]
                         Set Field [Orders::_fkAddressDestID ; $Temp]

                         Note that all changes have are made in the orders table.