Hi all.
I’m having trouble with my AfterQuery Datahooks.
Initially I set one up and it worked. However recently it seems to have stopped calling the hook code.
The hook combines the data from a number of fields, which is then used in a filter operation later. However the returned field (item.FilterFields) is always undefined.
I added a console.log to the hook, to see if it ever fires - and it does not appear to ever get called.
This is occurring with all of my afterQuery hooks.
Am I misunderstanding how these hooks should be used?
Any advice or direction would be appreciated.
data.js
export function PractitionerListing_afterQuery(item, context) {
//let hookContext = context;
console.log(item); //never prints to console
item.CountryAndState = item.country + " | " + item.state;
item.FilterFields = item.name + " " + item.practiceName + " " + item.country + " " + item.state + " " + item.city;
return item;
}
export function TrainingCourses_afterQuery(item, context) {
//TODO: write your code here...
console.log('training course after query hook'); //never prints
item.formattedStartDate = item.startDate.toLocaleDateString('en-GB', {
day: 'numeric', month: 'short', year: 'numeric'
});
item.formattedEndDate = item.endDate.toLocaleDateString('en-GB', {
day: 'numeric', month: 'short', year: 'numeric'
});
return item;
}
page code
$w.onReady(function () {
//Query to get the information from the database
wixData.query("PractitionerListing")
.find()
.then((results) => {
originalPropertiesInfo = results.items;
$w("#PractitionerRepeater").data = originalPropertiesInfo;
})
.catch((err) => {
let errorMsg = err;
console.log(err);
});
});
function filterResults(results){
const searchTerm = $w('#SearchInput').value;
if (searchTerm && searchTerm !== '') {
results = results.filter(item => item.FilterFields.toLowerCase().includes(searchTerm.toLocaleLowerCase()));
}
return results;
}