3 Replies Latest reply on Sep 25, 2012 8:58 AM by anothersmurf

    Going to a record when changing tabs

    anothersmurf

      Hello. I have a tabbed layout. When I change to a particular tab, I want to constrain my found set. I am able to do this much successfully by using the OnTabSwitch script trigger with a simple script that constrains the found set the way I want. So far so good.

       

      The problem is, the user ends up on the same record number as before the found set was constrained. If you were on record 8/100 before, you wind up on record 8/25 after, for example. What I want to do, though, is arrive at a record which corresponds meaningfully to the one the user started off on before changing tabs. Post-constrain, that's going to mean a different record number.

       

      So I modified my script. After the constrain, the script loops through the records until it arrives at the desired record, at which point the loop exits, leaving the user on the desired record.

       

      I know that the script works because I can step through it in Script Debugger when changing tabs. I can watch the script constrain the found set, and then loop through to the desired record.

       

      However, after the script ends, the tab switches and leaves the user on the wrong record. The found set is constrained as called for in the script, but it is as though the loop-to-desired-record part never happened. Even though I just watched it happen.

       

      So, is there any way to do this? ie arrive on a desired record at the end of a tab switch?

        • 1. Re: Going to a record when changing tabs
          CarstenLevin

          Before going to far:

          • What is happening when you use the debugger to step through the script.
          • Could you show the script here.
          • 2. Re: Going to a record when changing tabs
            anothersmurf

            Sure. It's a pretty short script...

             

            Set Variable $id, Table::IDfield

            If(GetValue(Get(TriggerTargetTabPanel), 1) = 1

                 Constrain found set (restore)

                 Go to Record [first]

                 Loop

                     Exit loop if Table::IDfield = $id

                     Go to next record

                 End Loop

            End If

            Set Variable $$YouAreHere to get(RecordNumber)

             

            That's it. NB the Constrain is done in such a way as to guarantee that an $id record still exists post-constrain. I didn't bother typing in what happens for switching to other tabs since it's not relevant here.

             

            If I switch to tab 1 with script debugger open, it runs through the script as expected. The Set Variable step at the end is just to make sure the script works. I switch tabs, the script runs, and before I step through that last Set Variable step, I can see that I am where I want to be. The variable is set, the script ends, the tab switches and the record jumps back to the record number that was showing before the script began executing.

             

            Just for fun, I threw a button onto the layout which does nothing but go go record number $$YouAreHere. If I switch to tab 1 and then click the stupid button, I end up on the record I want. I just (obviously) don't want to have to hit an extra button once the tab switch is complete.

             

            Edit to add: If I change the conditional to 1 (always true) and run the script manually (without changing tabs), when the script completes I am on the expected record.

            • 3. Re: Going to a record when changing tabs
              anothersmurf

              Well, OK, I found a way....

               

              Name your tabs. I use t1, t2, etc.

               

              Add a step to the end of the script that uses Go to Object to switch to the desired tab. (t & TriggerTargetTabPanel). Then, exit the script with result 0, which halts the (non-script) tab switch. That effectively turns the tab control into nothing but a button that runs your script.

               

              I don't know whether I'm working around a bug or a feature here, but if anyone else has this problem, there you go...

              1 of 1 people found this helpful