Jump to content

setResultLayout with Find Command


fmdataweb
 Share

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

Recommended Posts

I'm using setResultLayout for the first time so I can search on one layout with all the find fields on them but then switch to a much simpler layout with just the fields required for the search results. My search looks like this:

$request = $fm->newFindCommand('WebSearch');
$request->addFindCriterion('customerName', $_GET['contactName']);

$request->setRange($skip, $max);

// Set the layout to use for the Search Results
$request->setResultLayout( 'WebSummaryList' );
    
// 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();
}

--

I'm finding that when I include the line $request->setResultLayout( 'WebSummaryList' ) that my test for an error fails - if (FileMaker::isError($result)). I'm performing some finds with criteria that I know does not exist but the $findError variable is not getting populated (it returns 0 records). If I remove the line $request->setResultLayout( 'WebSummaryList' ) then the $findError variable is getting populated correctly.

Can anyone see what I might be doing wrong or is this expected behaviour etc?

thanks,

Steve

Link to comment
Share on other sites

You have to retrieve the field names on WebSummaryList:

$request->setResultLayout( 'WebSummaryList' );
$layout = $fm->getLayout( 'WebSummaryList');
$fields = $layout->getFields();
    
// Perform the Find
$result = $request->execute(); 

BTW, you have a slight error in your error detection statements.  The syntax for returning the error code is $result->getCode() . 

 

Link to comment
Share on other sites

16 hours ago, doughemi said:

You have to retrieve the field names on WebSummaryList:

$request->setResultLayout( 'WebSummaryList' );
$layout = $fm->getLayout( 'WebSummaryList');
$fields = $layout->getFields();
    
// Perform the Find
$result = $request->execute(); 

BTW, you have a slight error in your error detection statements.  The syntax for returning the error code is $result->getCode() . 

 

Thanks for the reply - I've just tried these changes but they make no difference. I can't see why you would have to retreive the fields names on the layout you specify in the setResultLayout method in any case.

Do you have a working example of where you use the setResultLayout method and are also able to successfully check for an error in the find command? 

BTW $result->code works just fine for retrieving the error code

Link to comment
Share on other sites

24 minutes ago, fmdataweb said:

 I can't see why you would have to retreive the fields names on the layout you specify in the setResultLayout method in any case.

My suspicion is that the PHP engine needs to be aware of what fields it can use for display after the search is performed. But I'm not sure about that.

As it so happens, I've got a search I'm playing with today where searching in one place and returning the data from another may be useful, so I'll check this at the same time...

Link to comment
Share on other sites

2 minutes ago, webko said:

My suspicion is that the PHP engine needs to be aware of what fields it can use for display after the search is performed. But I'm not sure about that.

As it so happens, I've got a search I'm playing with today where searching in one place and returning the data from another may be useful, so I'll check this at the same time...

Thanks webko, would be interested to see how you go. I can use setResultLayout successfully as part of my find request, but when I use it I lose the ability to check for an error in the find result for some reason. Let me know how you go - do a find you know will return 0 records and see if you can trap for that error.

Link to comment
Share on other sites

I've used setResultLayout before and it's pretty straightforward, hasn't messed with my error trapping, and should work the way you're using it. My guess is there is some other, unrelated issue. Try performing the find on WebSummaryList layout and see what happens.

When you view the WebSummaryList layout in layout mode, are there fields on it? (fields you added to the layout in Table View can't be accessed by CWP)

Link to comment
Share on other sites

18 minutes ago, dansmith65 said:

I've used setResultLayout before and it's pretty straightforward, hasn't messed with my error trapping, and should work the way you're using it. My guess is there is some other, unrelated issue. Try performing the find on WebSummaryList layout and see what happens.

When you view the WebSummaryList layout in layout mode, are there fields on it? (fields you added to the layout in Table View can't be accessed by CWP)

Thanks Dan for chiming in - I'd love to see an example of how you use setResultLayout in case there's an issue with my syntax here. Have you got a simple example you can share?

The WebSummaryList has fields on it and works just fine - I'm using it with the setResultLayout method successfully, but that combination causes me to not be able to check for an error with the find result which normally works fine.

Link to comment
Share on other sites

The code I use is highly abstracted. My error checking code, for example is in a function in a helper library. So, I don't think giving you snippets of my code would necessarily help. Your code looks the same as mine where it counts (except that I'm doing a compound find; not sure if that makes a difference here).

Have you tried viewing the $result after executing it? Sometimes seeing what's in the object can help. I used to use the firebug plugin for Firefox for this type of thing, but I think print_r() or similar could also work.

Link to comment
Share on other sites

Nice helper functions... Pity I spend most of my web time cleaning up other people's cruddy code in order to make it work, rather than writing from scratch.

and Yes, print_r($returnedFind); is very useful

Link to comment
Share on other sites

I've just run some tests by adding print_r($result) and here's what I get:

- if I include $request->setResultLayout( 'WebSummaryList' ); as part of the find command request and perform a find that returns 0 records I get a FileMaker_Result Object

- if I do NOT include $request->setResultLayout( 'WebSummaryList' ); as part of the find command request and perform a find that returns 0 records I get a FileMaker_Error Object

In both cases the found set is 0. This at least explains why I'm not able to return the error when including setResultLayout.

Can anyone else confirm this as well?

Link to comment
Share on other sites

On 1/11/2016 at 8:44 AM, webko said:

My suspicion is that the PHP engine needs to be aware of what fields it can use for display after the search is performed. But I'm not sure about that.

As it so happens, I've got a search I'm playing with today where searching in one place and returning the data from another may be useful, so I'll check this at the same time...

Hi webko,

Just wondering if you had a change to play with searching and using setResultLayout? 

Link to comment
Share on other sites

This topic is 2360 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.