Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

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

Recommended Posts

Posted

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!

Posted

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.

Posted

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?

  • 2 weeks later...
Posted

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

}

Posted

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.

  • 4 months later...
Posted

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.

Posted

Hard to tell without actually seeing the code in FileMakerService.php - exiting with a global variable obviously won't work though.

Posted

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.

This topic is 4833 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
×
×
  • Create New...

Important Information

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