perform script on server ("the script")..
Script Named "the script".....
-go to find mode
-do stuff with the found set
-exit loop if (condition)
*** error handling not in the prototype above ***
What happens in "the script" stays inside the context of the server unless you are setting non global fields in do stuff or you pass results out with exit script(return)
Just like you would do in a normal user's session...
If there is something specific in the real user's session that is necessary for the PSoS session then pass it along to the server script as a parameter.
Perform script on server (PSOS) is not a swiss knife to all your speed problems. It has to make sense using it. And you have to remember that your database opening script, if any, will be run every time you use PSOS, before the script that you are PSOS'ing.
Having said that, you can have a script 1:
Exit Script[ExecuteSQL("SELECT ID from Customers WHERE ZipCode = ?" ;"";""; Get(ScriptParameter) ) ]
and a script 2:
Perform Script on Server(script 1) with parameter: ZIPCode
Set Variable [ $SameZIPCodeCustomers; Get(ScriptResult) ]
at this point you can loop on the values in $SameZIPCodeCustomers, from 1 to ValueCount(), and do things on those customers.