Donald P
Donald P

Reputation: 853

Execute Script and Return Result

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 ScriptResult 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.

Upvotes: 0

Views: 1442

Answers (1)

user982124
user982124

Reputation: 4610

An important point to note about the FileMaker PHP API and performing FileMaker scripts is When you run a FileMaker script with PHP FileMaker sends back the found set when the script completes. So all you need to do is make sure that you end up with a found set of just the new record you have created as a found set of 1 record, and that will be returned to the PHP script.

Upvotes: 1

Related Questions