2 Replies Latest reply on Oct 28, 2016 9:04 AM by philmodjunk

    Copy data from portal row to current record



      Windows 10 FMPA 14


      I think I am in brain freeze.


      I have a script,  that when it is triggered, I want it to look for a matching field in the portal row on that record.  If a match exist, to then bring each item from that row in to fields in the current record.


      How do I find that matching portal row, then copy the data form the fields in that row, while staying on my current record?


      I think I have done this before but I am drawing a blank!


      Thanks for any help!!

        • 1. Re: Copy data from portal row to current record

          Go To Object [ portalobjectname ]

          Go To Portal Row [ first ]


               If [ portaltable::portalfield = "match condition" ]

                    Set Variable [ $copy ; whatever you want to copy ]

                    Exit Loop If [ true ]

               End If

               Go To Portal Row [ Next ; exit after last ]

          End Loop

          If [ isempty ( $copy ) ]

               Show Custom Dialog [ "no match was found" ]


               Set Field [ parenttable::destination ; $copy ]

          End if

          That should do it. Augment as needed for additional fields.

          • 2. Re: Copy data from portal row to current record

            I would as a general rule avoid looping through portal rows in the first place as this produces a script that easily "breaks" when sometimes even minor layout changes are made at some point in the future.


            There are other and (in my opinion) better options.


            ExecuteSQL might be used to return the portal record's primary key. You set a field in your parent record to that value and your fields, if set up with auto enter field options (calculations or looked up values) to copy over the needed data.


            You might use a new and "off screen" window to pull up a found set of portal records and loop through them. (but this can still trip at least two script triggers on your current layout.)


            You might use List to get a list of Primary keys from your portal and use a global field to point to one record at a time in a loop to check each value in turn. In all three of these, all you really need to get is that Primary Key.


            All of the above methods enable you to search out a value while being much less sensitive to layout changes that might cause your script to fail at some point in the future.