4 Replies Latest reply on May 2, 2016 1:09 PM by macaque

    How can I stop portal records being sorted while a script is running?

    macaque

      I have a problem with portal records sorting while my script is running such that results get entered into the wrong record. I thought recent versions of File Maker (I'm using 14) prevented sorting while scripts are running.

       

      I have a layout with several tabs and one of these contains a portal of records intended to manage staff holidays on a rota. The user enters a start and end date for the leave period and ticks a checkbox. This triggers a script that applies the date range to the rota and returns with the number of work shifts affected.

       

      During my testing I entered dates for March and April and then added one for January. The script toddled off to do its bit but on returning to the original layout and tab, the January dates had sorted themselves to the first portal row and so the script result overwrote April's entry. The only way I can stop this is to remove the portal's sort paramter (by leave start date) but I'd like to keep that 'cos it looks nice.

       

      My script saves the active portal row to a variable $APR before going to the Rota layout. Here are the steps on its return:

       

      ...

      Go to Layout [ original layout ]

      Go to Object [ Object Name: "LeaveTab" ]

      Go to Portal Row [ No dialog ; $APR ]

      Set Field [ Leave::ShiftsAffected ; $ShiftCount ]

      Exit Script [ ]

       

      By inserting pauses in various parts of my script I can see that the sort occurs just after Go to Object. I've tried adding an Unsort Records command just after this point but it doesn't help. Any ideas?

        • 1. Re: How can I stop portal records being sorted while a script is running?
          danielfarnan

          I'm not sure if there's a way to prevent the portal from sorting during the script operation; I doubt it's possible.

           

          I think what's tripping you up is the assumption that the row number will uniquely identify the related record you wish to return to - as you've found out, that's an unreliable method. I would instead get the primary key of the related record from the portal before going to the Rota layout and store that in the $APR variable.

           

          In your snippet above, after the Go to Object step, issue a Go to Portal Row [ First ] and then:

          Loop

              Exit Loop If [ <appropriate primary key> = $APR ]

              Go to Portal Row [ Exit After Last ; Next ]

          End Loop

          If [ <appropriate primary key> = $APR ]

              Set Field [ Leave::ShiftsAffected ; $ShiftCount ]

          End If

          Exit Script [ ]

           

          There's probably some more error checking you can do, but this should provide most of what you want.

          1 of 1 people found this helpful
          • 2. Re: How can I stop portal records being sorted while a script is running?
            erolst

            Save the primary key, and on returning …

             

            either loop until you find it …

             

            Set Variable [ $id ; Portal::id ]

            Go to Object

            Go to Portal Row [ first ]

            Loop

            Exit Loop if [ $id = Portal::id ]

            Go to Portal Row [ next ]

            End Loop

             

            … or use this calc with Go to Portal Row [ by calculation ]:

             

            Let (

              IDList = List ( Portal::id ) ;

              ValueCount ( Left ( IDList ; Position ( ¶ & IDList & ¶ ; ¶ & $id & ¶ ; 1 ; 1 ) ) )

            )

            1 of 1 people found this helpful
            • 3. Re: How can I stop portal records being sorted while a script is running?
              siplus

              Generally having a Freeze Window as first line of your scripts is a good thing.

              • 4. Re: How can I stop portal records being sorted while a script is running?
                macaque

                Thanks for the assistance. I've used the primary key method and also used the "Leave" layout rather than the portal for updating because I intend to have two portals - one for this year and one for next - and filter the view on year value. No doubt that will bring its own problems!

                 

                I had included the Freeze Window command in my script but that didn't help with the problem.

                 

                Thanks again.