Jump to content

Can Script Results Be Returned?


Thirdwaver
 Share

This topic is 4180 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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!

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • 2 weeks later...

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...";

}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 4 months later...

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.

Link to comment
Share on other sites

This topic is 4180 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.