tinynumbers Posted November 19, 2008 Posted November 19, 2008 (edited) I was hoping that within a Groovy script I could do something like this: fmpro.performScript(fileName, scriptName, scriptParam); result = fmpro.evaluate("Get ( ScriptResult )"); ... However, it appears that calling fmpro.performScript(...) triggers the FM script asynchronously - i.e., the FM script will be on a different thread, so the Groovy script doesn't wait for the script to complete before it continues on to the fmpro.evaluate(...). So the fmpro.evaluate of "Get ( ScriptResult )" just sets "result" to an empty value, since the FM script hasn't completed (and therefore hasn't returned its value yet). So, that being the case, does anyone have any other suggestions on how to go about this sort of thing? Is there any way to get the fmpro.performScript(...) call to evaluate synchronously, or to wait in the Groovy script until the FM script finishes? Edited November 19, 2008 by Guest
Jesse Barnum Posted November 19, 2008 Posted November 19, 2008 No, you can't do what you're trying to do for 2 reasons: 1) FileMaker cues all scripts asynchronously. There is an order of operations that all user actions get processed in, and script execution is near the end. This is why, for example, you can mess up any FileMaker script triggering plugin by modifying a field value in record 1 and then using the rolodex to flip to record 2 instead of tabbing out of the field. The plugin receives the event from FileMaker while the user is still on record 1, and it can tell FM to execute a script, but FM ignores that request until it flips to record 2, and then it will run the script, resulting in the the script executing on the wrong record. It is of course possible to work around this problem by passing in a script parameter for which record to operate on, but that's a separate issue. 2) Get( ScriptResult ) only works for scripts, not plugins. You can not call this outside of the context of a running script. For example, if you put it in the data viewer, it will always return an empty result (unless maybe you're running in script debugger mode). It is possible for you to trigger the FileMaker script, and when that script is done, it could then trigger some ScriptMaster function to post-process the result. This is how I would do it.
tinynumbers Posted November 20, 2008 Author Posted November 20, 2008 Makes sense, and that's what I thought must be the case from my experiments with this. Thanks for the details, and for the suggestions on alternative approaches.
Kris M Posted November 20, 2008 Posted November 20, 2008 Is their a doc or whitepaper that defines this "order of operations" that you mention? TIA K
Jesse Barnum Posted November 20, 2008 Posted November 20, 2008 No, this is just based on my observations.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now