2 Replies Latest reply on Jan 13, 2016 7:19 PM by user19752

    Filemaker/PHP execute script result

    dpistole

      Title

      Filemaker/PHP execute script result

      Your post

      I have a PHP script that interacts with the Filemaker API (FM Server 13).

      The idea is that a user clicks a a link on a webpage, which submits a request, PHP triggers a Filemaker script that generates a document, and then the user is redirected to a page where they can download the doc that was generated by filemaker.

      As a side note, the script that is triggered performs another script using "Perform Script on Server", and that script generates the doc and returns the doc ID to the parent(originally triggered) script. This portion seems to be working OK. The doc is generated, the ID is returned, and I store the doc ID as part of a 'ScriptResult' record.

      I cannot figure out how to get the doc ID back into PHP. In PHP the result object that returns from the execute script command usually has two records. One being the newly created Script Record, and the other being some random 'ScriptResult' record. If I comment out the part that generates the new 'ScriptResult' record, I still get some random older 'ScriptResult' record for some reason ( I cannot figure this out, and it seems random as it changes every request and does not appear to be incremental or anything. )

      A simplified version of the filemaker script looks like...

      Set Variable [$params, Value(Get(ScriptParameter))]
      Perform Script on Server["generate_doc" from file: "FM_File"; Parameter: $params]
      Set Variable [$result; Value:Get(ScriptResult)]
      New Record/Request
      Set Field[scriptResult::docID; $result]
      Commit Records/Requests[]


      ..and what I get back is a Result object, with multiple records, one of which is the ScriptResult I've created, and the other seems to be some random ScriptResult. I only want the newly created ScriptResult back, so that I can pull the document ID field from it.

      Any input is appreciated

      http://stackoverflow.com/questions/29402803/filemaker-php-execute-script-and-return-result

        • 1. Re: Filemaker/PHP execute script result
          davidrcrowe

          As far as I can tell there is no usable way to get feedback from a FileMaker script executed via the PHP interface. I tried at first to write the result to a global, but globals are for a single context, and the PHP context is different than the context the script runs in (it doesn't have to be that way, but it is). So I then thought of a regular non-global field, but the problem here is that if two users run a script using this method on the same record, one of the scripts will get the wrong result back. It looks to me that the PHP interface was designed when FM scripts couldn't return a result (but could accept parameters). And the PHP interface was never updated, because FM doesn't care about it.

          • 2. Re: Filemaker/PHP execute script result
            user19752

            I didn't tested, but your link shows the answer, doesn't it? Before "New Record" add something like

            Go to Record[First]

            Omit Records[Get(FoundCount)]

            to make sure the record just created is only one in found set.