1 Reply Latest reply on Jul 10, 2017 2:20 AM by User26869

    FileMaker PHP API - newPerformScriptCommand and Script Errors

    fmdataweb

      I'm trying to understand what could generate an error when performing a FileMaker script from via the PHP API using the newPerformScriptCommand command, e.g.

       

      $scriptObject = $fm->newPerformScriptCommand($layoutName, $scriptName, $scriptParams);

      // Execute the script

      $scriptResult = $scriptObject->execute();

       

      if(FileMaker::isError($scriptResult)) {

      // FileMaker PHP API Error -- Alert User.

      $scriptError = 'Perform Script Error: '. $scriptResult->getMessage() . ' (' . $scriptResult->code . ')';

      } else {

      // no error - continue on

      }

       

      I realise that if any of the newPerformScriptCommand parameters have errors like an invalid layout name or script name it will return an error, but I'm more interested in when the actual FileMaker script encounters an error when will it cause $scriptResult to return an error? For example I was just using this to call a FileMaker script - there was an issue with the FileMaker privileges for a table I was trying to create records in, but the script executed correctly as far as the PHP API was concerned. I only found out about the issues by looking at the Log Viewer in the FileMaker Server Admin Console after noticing the records were not being created.

       

      Is there a way to exit the FileMaker Script with a script result that will generate an error with the $scriptResult? Do any FileMaker Script steps cause errors that will lead to an error result when executing the newPerformScriptCommand command?

        • 1. Re: FileMaker PHP API - newPerformScriptCommand and Script Errors
          User26869

          Hi !

           

          What you could do if capture the errors after each important script steps (like create a new record) using Get(LastError) - you could save the error and the step it happened to in a variable and at the end of the script, set this variable to a global field that you can access using the PHP API.

          So this would be:

          if(FileMaker::isError($scriptResult)) {

          // FileMaker PHP API Error -- Alert User.

          $scriptError = 'Perform Script Error: '. $scriptResult->getMessage() . ' (' . $scriptResult->code . ')';

          } else {

          // no error - check for global field

          // if global field with script errors is empty, continue

          // if not, show which error.

          }

           

          Hope this helps!

          1 of 1 people found this helpful