I am trying to create a search on a collection using one of the fields that is a reference item. I have created many other searches before on regular fields and it works fine, but the reference field seems to have difficulty. I have reviewed several posts here and implemented their suggested solutions but none of them seem to work.
Summary: I have a data collection of “SalesReps”. Fields include the rep name as well as other items.
2nd collection is “Accounts” which includes a reference field called “salesrep” with a single reference to the item in the first collection.
I want to select the rep from a drop down list and then show all accounts assigned to that rep. I can populate the drop down very easily, but my results from the account search show all results without any filter or .eq ( I have tried numerous variations).
Any HELP is greatly appreciated.
export function salesrepfilter_change(event) {
// Code to lookup customers in the database and populate table
$w( “#pleasewait” ).show();
wixData.query( “SalesReps” )
.eq( “salesRep” ,$w( “#salesrepfilter” ).value)
.find() // Run the query
.then( (results) => {
if (results.items.length > 0 )
{
salesreprecord = results.items[ 0 ];
salesrepID = salesreprecord._id;
$w( “#accountdataset” ).setFilter(wixData.filter()
.eq( “salesrep” , salesrepID));
}
else
{
// handle case where no match found - message on screen
}
}
);
wixData.query( “Accounts” )
// Query all of the accounts for the selected sales rep
.include( “salesrep” , “group” , “type” )
.find() // Run the query
.then( (results) => {
if (results.items.length > 0 )
{
// Set the table data to be the results of the query
$w( “#customers” ).rows = results.items;
$w( “#pleasewait” ).hide();
}
else
{
// handle case where no match found - message on screen
}
});
$w( “#pleasewait” ).hide();
}