SetFilter not filtering dataset on dynamic page

I have a dynamic page and the dataset is functioning properly when I don’t pass in any URL parameter. Today I setup a Source variable that pulls in a source param from the URL. When this param is provided, I set it to run the SetFilter and display the updated repeater:

if ( typeof wixLocation.query.source !== ‘undefined’ ){
source = wixLocation.query.source;
console.log( “source is populated with: [” + source + “]” );
}

if (source=== “” ){
//do nothing
console.log( “source is empty” );
$w( ‘#dynamicDataset’ ).setFilter( wixData.filter() );
$w( “#listRepeater” ).expand();
$w( “#listRepeater” ).show();
$w( ‘#group6’ ).show();
$w( ‘#group7’ ).show();
$w( ‘#group8’ ).show();
} else {
$w( ‘#group6’ ).hide();
$w( ‘#group7’ ).hide();
$w( ‘#group8’ ).hide();
console.log( "source = " + source);
$w( ‘#sourceaccount’ ).value = source;
$w( “#dynamicDataset” ).onReady( () => {
$w( ‘#dynamicDataset’ ).setFilter( wixData.filter()
//.eq(“Username”, “honey_morgan09”)
.startsWith( ‘Username’ , source)
)
.then( () => {
console.log( “Dataset is now filtered and visible set to: " + $w( “#listRepeater” ).isVisible);
$w( “#listRepeater” ).forEachItem( ($item, itemData, index) => {
count = count + 1 ;
} );
console.log( “count total = " + count);
$w( “#listRepeater” ).expand();
$w( “#listRepeater” ).show();
//$w(”#dynamicDataset”).refresh();
} )
. catch ( (err) => {
console.log(err);
} );
} );

} 

I’m successfully getting the Source value in the log, indicating that the startsWith has the correct value. Even when I uncomment the line above it and feed in a hardcoded value, the dataset is still not filtering. I double checked using a counter inside the forEachItem and there’s no result set, so the count remains zero.

You misspelled the field key (or used the filed label instead) when you tried to set the filter.
On Wix collections, field keys never start with a capital letter (“Username” is not a valid field key. try “username” instead).

Thx, its working now!

You’re welcome :slight_smile: