Thirdwaver Posted March 16, 2011 Posted March 16, 2011 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!
iMarcW Posted March 17, 2011 Posted March 17, 2011 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.
Thirdwaver Posted March 17, 2011 Author Posted March 17, 2011 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?
Genx Posted March 30, 2011 Posted March 30, 2011 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..."; }
Thirdwaver Posted March 30, 2011 Author Posted March 30, 2011 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.
Slowfib Posted August 26, 2011 Posted August 26, 2011 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.
Genx Posted August 28, 2011 Posted August 28, 2011 Hard to tell without actually seeing the code in FileMakerService.php - exiting with a global variable obviously won't work though.
Slowfib Posted August 29, 2011 Posted August 29, 2011 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.
Recommended Posts
This topic is 5091 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now