March 16, 201114 yr I'm wondering if there is any way to access the script results from PHP after the script is executed. Like in the FMPro script, if I put an "Exit Script" command and type in some script results, are those accessible to PHP after the PHP executes that script? If so, how? Thanks!
March 17, 201114 yr Perhaps you could write the result to a global field (make sure it's on your target layout) and get the field contents like you would any other field.
March 17, 201114 yr Author Hmm. That's an interesting thought. My only concern would be timing. The script would take x number of seconds to complete while the PHP would immediately query the global and probably find it empty. How do globals work on the web? Does each PHP session get its own? When is it "destroyed" so to speak?
March 30, 201114 yr You'll have to experiment but here are the following notes (based on default settings): 1) If you perform a script as a command and then as a seperate command try and retreive what was stored in the global, the global will be empty. 2) If you perform a script as part of a command (e.g. after a find command for a single specific record), you will receive back a result object containing the record that you found as such: a) Find some record (any record) (e.g. $find = $db->newFindAnyCommand() ) b ) As part of the find command, perform a script ($find->setScript('scriptname','param')) (this script well set "someglobal" to a value) c) Execute the command ($result = $find->execute()); d) From the result object, get the record ($record = $result->getFirstRecord()) e) Retreive the value from the global field ($record->getField("someglobal") Put it all together and you get: $find = $db->newFindAnyCommand("MyLayout"); $find->setScript("MyScript"); $result = $find->execute(); if( !FileMaker::isError($result) ){ echo "The value in the globa field set by the script is... " . $result->getFirstRecord()->getField("someglobal")." yay..."; }
March 30, 201114 yr Author You'll have to experiment but here are the following notes (based on default settings): 2) If you perform a script as part of a command (e.g. after a find command for a single specific record), you will receive back a result object containing the record that you found as such: a) Find some record (any record) (e.g. $find = $db->newFindAnyCommand() ) b ) As part of the find command, perform a script ($find->setScript('scriptname','param')) (this script well set "someglobal" to a value) c) Execute the command ($result = $find->execute()); d) From the result object, get the record ($record = $result->getFirstRecord()) e) Retreive the value from the global field ($record->getField("someglobal") Brilliant! Thank you very much! I'll give that a try.
August 26, 201114 yr I'm trying to do the same thing here. I know PHP really well, but have just been introduced to FM. Genx, I tried your solution, but what I get as my results are: Notice: Undefined offset: 0 in C:\inetpub\FileMaker\Implementation\ResultImpl.php on line 41 Fatal error: Call to a member function getField() on a non-object in C:\FileMakerService.php on line 337 My FM script is: Set Variable [$$someglobal; Value: "success"] Exit Script [Result: $$someglobal] Any ideas? Thanks.
August 28, 201114 yr Hard to tell without actually seeing the code in FileMakerService.php - exiting with a global variable obviously won't work though.
August 29, 201114 yr Actually, it was my fault, I was thinking global 'variable' not global 'field'. I know PHP, but am new to FM and just trying to sort out how I work with layouts, scripts, etc.. Thanks for the quick response though.
Create an account or sign in to comment