Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Can Script Results Be Returned?

Featured Replies

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!

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.

  • 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?

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

}

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

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

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.