databuzz

FileMaker PHP API - setResultLayout method and FileMaker_Error Object

Discussion created by databuzz on Feb 3, 2016
Latest reply on Feb 16, 2016 by TSGal

Product and version: FileMaker Server 14.0.4.413

 

OS and version: Mac OS X 10.10.5

 

Description:


Using the setResultLayout method with a find command with the FileMaker PHP API does not return a FileMaker_Error Object when there is a find error (e.g. no records found). Instead it returns a FileMaker_Result Object. This means you are unable to check for a find error in the typical way, e.g.:

   

if (FileMaker::isError($result)) {

    if ($result->code = 401) {

    $findError = 'There are no Records that match that request: '. ' (' . $result->code . ')';

    } else {

    $findError = 'Find Error: '. $result->getMessage(). ' (' . $result->code . ')';

    }  

} else {

$records = $result->getRecords();

}

 

There is a post in the FileMaker Community about this same issue here:

Re: FileMaker PHP API - setResultLayout with Find Command


How to replicate:

 

Create a find command like the following that will return 0 records like the following:

 

$fm = new FileMaker('FMPHP_Sample');

 

$request = $fm->newFindCommand('Form View');

$request->addFindCriterion('Title', 'xxxxyyyzzz');

 

// Set the layout to use for the Search Results

$request->setResultLayout( 'WebSites' );

   

// Perform the Find

$result = $request->execute();

   

if (FileMaker::isError($result)) {

    if ($result->code = 401) {

    $findError = 'There are no Records that match that request: '. ' (' . $result->code . ')';

    } else {

    $findError = 'Find Error: '. $result->getMessage(). ' (' . $result->code . ')';

    }   

} else {

$records = $result->getRecords();

}

 

If you examine the $result object you will find that it is FileMaker_Result Object so checking for a find error using " if (FileMaker::isError($result)) { " won't work.

 

If you remove the line "$request->setResultLayout( 'WebSites' );" you will get a FileMaker_Error Object which you can retrieve the find error code etc from.

 

Workaround (if any)

Outcomes