Jump to content
Server Maintenance This Week. ×

About Compound FindCommand


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

Recommended Posts


$compoundFind =& $fm->newCompoundFindCommand('Accounts');

$findreq1 =& $fm->newFindRequest('Accounts');

$findreq2 =& $fm->newFindRequest('Accounts');

$findreq1->addFindCriterion('acctype', 'User');

$findreq2->addFindCriterion('squestion', '1');

$compoundFind->add(1,$findreq1);

$compoundFind->add(2,$findreq2);

$result = $compoundFind->execute();

When i use the above compoundfind, I found all the records where the acctype=User also squestion=1

But i need the the records where acctype=User and squestion=1 (refer attached image: I need 2 records only which is marked in green color)

Please help me to alter the above find code to attain my solution

capture.png

Link to comment
Share on other sites

Compound Find requests perform an or search (Criterion1 OR Criterion2). You only need the normal newFindCommand to perform an and search (Criterion1 AND Criterion2):


$findreq =& $fm->newFindCommand('Accounts');

$findreq->addFindCriterion('acctype', 'User');

$findreq->addFindCriterion('squestion', '1');

$result = $findreq->execute();

Link to comment
Share on other sites

In this case, you are looking to find records in which acctype="User" OR acctype ="Family". (it is impossible in this instance to have a record in which acctype contains both "User" AND "Family"). Thus, you would use the Compound Find structure:


$compoundFind =& $fm->newCompoundFindCommand('Accounts');

$findreq1 =& $fm->newFindRequest('Accounts');

$findreq2 =& $fm->newFindRequest('Accounts');

$findreq1->addFindCriterion('acctype', 'User');

$findreq2->addFindCriterion('acctype', 'Family');

$compoundFind->add(1,$findreq1);

$compoundFind->add(2,$findreq2);

$result = $compoundFind->execute();




I would recommend that you research "Boolean AND and OR operators" to build your understanding of these important tools.  These operators have much more specific definitions than the common usage of the English words they are based on.



Now, if you were conducting a search for records which have either "User" or "Family" in the acctype field and at the same time have 1 in the squestion field, you would have to expand the Compound Find structure:



$compoundFind =& $fm->newCompoundFindCommand('Accounts');

$findreq1 =& $fm->newFindRequest('Accounts');

$findreq2 =& $fm->newFindRequest('Accounts');

$findreq1->addFindCriterion('acctype', 'User');

$findreq1->addFindCriterion('squestion', '1');

$findreq2->addFindCriterion('acctype', 'Family');

$findreq2->addFindCriterion('squestion', '1');

$compoundFind->add(1,$findreq1);

$compoundFind->add(2,$findreq2);

$result = $compoundFind->execute();

Link to comment
Share on other sites

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