AfterQuery data hook not firing

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;
}

The afterQuery() hook occurs after a query. However, I don’t see a query in the code that you’ve posted.

Good point. Post edited to include the query.

I worked out the problem. - which maybe could have been sorted earlier if I’d thought to include the import statements.
I wasn’t seeing any errors in the console when viewing my live site, but when I previewed the site, I got an error that tipped me off - “wix-users could not be found” - or something like that

Turns out I was using the wrong wix users lib
I was using this:
import wixUsers from ‘wix-users’;

Instead of this.
import wixUsersBackend from ‘wix-users-backend’;

Problem solved!