5 Replies Latest reply on Feb 26, 2011 2:19 PM by TimMatthews

    Need script trigger advice

    TimMatthews

      Title

      Need script trigger advice

      Post

      I have a script that i want to run automatically when I exit a portal. The script sets a value to a field within a portal depending on the portal row number. The script works fine if I run it manually but I want it to run automatically when I exit the portal but when I set it to run on exit it gets caught in a loop and I have to exit FMP to stop it.

      The script looks like this where "portaltable" is the table the portal points to and "portalfield1/2" are the fields in the portal table

      Go to Portal Row [ Select; First ]

      If [ not IsEmpty(portaltable::portalfield1) ]

      Set Field [portaltable::portalfield2; "1" ]

      Go to Portal Row[ Select; Next ]

      If [ not IsEmpty(portaltable::portalfield1) ]

      Set Field [portaltable::portalfield2; "0.5" ]

      Loop

      Go to Portal Row[ Select; Next; Exit after last ]

      Exit Loop If [ IsEmpty (portaltable::portalfield1) ]

      Set Field [portaltable::portalfield2; "0.25" ]

      End Loop

      End If

      End If

      Now as I said it works when I run it manually but I need help in setting an appropriate script trigger or tweeking the script in order to get it to run on exit from the portal.

      Hope this makes sense

      Tim

       

       

        • 1. Re: Need script trigger advice
          Sorbsbuster

          BTW: rather than exiting FM, you could try hitting the Escape key to exit the loop.

          • 2. Re: Need script trigger advice
            philmodjunk

            Use a global field to disable the trigger from firing a second time:

            IF [ not $$NoTrigger]
               Set Variable [$$NoTrigger ; value: True]
               //Put the rest of your script here
            Else
               Set Variable [$$NoTrigger; Value: False]
            End If

            • 3. Re: Need script trigger advice
              TimMatthews

              Sorbsbuster - Thanks, I know about the esc to stop the script however this leaves me inside the portal and when I try to do anything it exits the portal and runs the script again, I hit esc and the problem is again there.....

              PhilModJunk - i have tried what you suggested but it still does it, I'm fairly new at this so it's probably pretty easy answer. Should I have a field in my table that is "NoTrigger",  and should the If statement have not $$NoTrigger = Something???

              • 4. Re: Need script trigger advice
                philmodjunk

                Hmm, that just taught me something new.

                OnObjectExit for a portal fires when you exit a portal row rather than the entire portal.

                Each time your script does a go to portal row, it trips the OnObjectExit trigger and thus even using the global variable doesn't work as written because it keeps resetting the value of the variable and this re-enables the script. 

                You have to keep reseting the global field each time there's a go to portal row and you have to manage to exit the portal, then cancel the original trigger to keep it from starting up all over again.

                IF [ not $$NoTrigger]
                   Set Variable [$$NoTrigger ; value: True]
                   Go to Portal Row [ Select; First ] 
                   Set Variable [$$NoTrigger ; value: True]
                   If [ not IsEmpty(portaltable::portalfield1) ]
                       Set Field [portaltable::portalfield2; "1" ]
                       Go to Portal Row[ Select; Next ] 
                       Set Variable [$$NoTrigger ; value: True]
                       If [ not IsEmpty(portaltable::portalfield1) ]
                               Set Field [portaltable::portalfield2; "0.5" ]
                               Loop
                                       Go to Portal Row[ Select; Next; Exit after last ] 
                                       Set Variable [$$NoTrigger ; value: True]
                                       Exit Loop If [ IsEmpty (portaltable::portalfield1) ]
                                       Set Field [portaltable::portalfield2; "0.25" ]
                               End Loop
                       End If
                   End If
                   Commit Records/Requests
                   Set Variable [$$NoTrigger ; value: False]
                   Exit Script [ False ]
                End If

                That took a lot of runs with the debugger before it all worked more or less. The "or less" is that it now takes two clicks to click into a different portal row if you already have the cursor inside a field in the portal row.

                • 5. Re: Need script trigger advice
                  TimMatthews

                  Phil

                  Thanks heaps works exactly like I need it too. Also I don't seem to have the problem of having to double click to get to a different portal row.... must have done something wrong/right when I copied your new script.