3 Replies Latest reply on May 24, 2012 10:11 AM by Stephen Huston

    Problem Running Scripts from the server


      Hi there...


      I have a script that works fine when running from the client, but when I run it from the server as a scheduled script it sometimes hangs. Are there things I need to be careful about when running a script from the server? It's frustrating because I can not use the Script Debugger to figure out why it is hagning up.





        • 1. Re: Problem Running Scripts from the server

          Hi Eric,


          You haven't given much information about what your script is doing, but there are things you need to be extra careful about when running a server scripts.  The fact it sometimes hangs is more than likely due to a record lock happening and you aren't handling it correctly - the script thus getting stuck on the record it's trying to edit, but can't - then you try to leave the record / layout and this fails because it's stuck on the record it can't save.


          Some other ideas :


          1) Do you have a script set to run on opening the file (or perhaps a related file) ?  This could be running and executing code you aren't expecting.   In my opener scripts,  the first line is a 'if[ (patterncount( Get( ApplicationVersion ) ; "Server" ) > 0) or (patterncount( Get( ApplicationVersion ) ; "Web" ) > 0) ]' with a 'Exit Script' inside.


          2) Be anal whenever you edit a field / record.  If you edit a field, make sure it has a 'Commit Record'.  Also, check for an error and Revert the edited record if you get an error.   This is especially important if you are in a loop as you may never exit it.


          3) In loops,  use a SetVariable[ $loop ; Get( FoundCount ) ]  and in the loop, use a 'ExitLoopIf[ Let( $loop = $loop - 1 ; $loop <= 0 ) ]'

          That way, you'll never end up in a loop that you never leave.


          4) Check (I'm sure you have already) the server logs for any errors.  It may be there is an error reported that'll give you a clue.


          5) In your scripts - toggle the show script steps to the 'Server' setting - are you sure you haven't included a non-server supported script step ?   They may get ignored - but this could have an undesired effect.


          6) You may not be able to use script debugger - but you can add some logging to your server script  (never a bad idea).   Create a log table and a script which adds a record to it with the log data.  Make sure your log script restores the calling layout so you don't introduce a new bug



          Hope this helps



          • 2. Re: Problem Running Scripts from the server

            Wow, thanks for all of those great ideas - you have given me a bunch of stuff to check...


            I'll try to remember to come back and update this when I find out what's going on...



            • 3. Re: Problem Running Scripts from the server
              Stephen Huston

              Also keep in mind that if your script accesses data which is on multiple FM Server machines, it MUST be run from a Client as no FM Server can read data on a different FM Server.