4 Replies Latest reply on Jan 28, 2012 12:49 PM by mbust

    How to keep script from skipping steps when called from PHP page?




      Can someone please help me find the answer to this problem? I have a script that does a server side search, then, on the found set, it sorts, goes to the first record and replaces a field (FoundQuery) with the number 1 for the entire found set. (That way, a PHP search can just search another layout for the 1 in that field, and not in the original, very large field. This makes the search quicker since the new layout only has to contain a field with a number one and a few other pieces of information, instead of the original field that contains about 25K characters per record). The problem I have is that when I run the script through PHP, the script skips steps, including the replace step (which is set to not display the dialog box to be server compatible). Most of the script runs fine, otherwise, and completes without complaining. If I run the script directly (by opening the database remotely), the script runs just fine without skiping any steps. I woud love to find a way to correct this. A slower path, telling the script to loop through the records, also skips and does not replace any fields, even if I use the commit command. The odd thing is that the script does run, variables before and after these steps to declare, and other steps work fine.


      I'm running FM Pro 11 Advanced.


      Thanks for any help anyone can give me.

        • 1. Re: How to keep script from skipping steps when called from PHP page?

          mbust, can you perform the same actions in the first script with just php?


          If not, how are you calling the script? Can you post any of your code?


          -- sent from my iPhone4 --

          Beverly Voth


          • 2. Re: How to keep script from skipping steps when called from PHP page?

            Hi Beverly,


            Thanks for answering.  Yes, it is possible, I suppose (but I'm a beginner with PHP).  I could run a simple search from PHP that returns all the records that I need to find (I can do that).  But the search is very slow because the database contains a large number of articles, and each article is between 16K to 25K characters, so returning all those characters from that query can take sometimes ten minutes or longer.  I would like to search using PHP instead of a FM script, but I would need to change layouts with PHP and don't know how. (So only the title of the article is returned, not the actual text of the article that was searched). As I understand, FX.php can search one layout and return another, but not the API.  If there were a way to do this using only the API (as I said, to do a search in a layout and then return the results using another), I would love to know how. 


            In any case, I'm very much frustrated that a FM script will execute to the end but skip steps in the middle.  That seems to me to be problematic.  It should break and let you know, but not keep executing steps as if nothing had happened, especially, if all the steps are server-compatible.


            Thanks for the help!

            • 3. Re: How to keep script from skipping steps when called from PHP page?

              There are two types of errors a server can encounter when running a script: an unsupported script step or a script step that returns an error code. For example, Server can't respond to dialogs so any script step that is set to produce a dialog is not supported. While Perform Find[] is supported it could return an error just as it would while running on the client.


              Setting Allow User Abort[] to On will abort a Server script if it encounters an unsupported script step. General error handling should be used to deal with the second type of error. Use Error Capture [On] and deal with errors as they could happen.


              Specifically with your problem, I'd look in two places:

              1) Is the "Perform without dialog" checkbox checked on the Replace Field Contents[] script step?

              2) Are you sure you have a found set to operate on?


              You can test #1 by adding some tests to your script. For example, you could set a utility field to the found count and then exit.


              You can also get some clues on the PHP side by using echo and the variable you used to call the FM script.

              1 of 1 people found this helpful
              • 4. Re: How to keep script from skipping steps when called from PHP page?

                I got it!  It was a permissions problem.  I had been running with error capture on, and had tracked some of the errors (actually no error), but after your email, I added a number of variables just after the problematic steps (should have thought of that earlier!), and sure enough, I was running remotely with a different set of privileges than I was testing with PHP, so PHP was tripping (error 200, access denied). 


                Thanks for the help!