I have a number of tables used to drive repeating elements on dynamic pages. For ease of data entry I wanted to use a reference on a number of fields. However as it appears that filters on dynamic pages cannot filter on references I have been building filter and sequence columns in a usable format (string or number) from data that is entered into reference fields.
To do this I have been using the data hooks in data.js.
At one point it was possible to access the values in the reference field using the following form:
item.filterColumn = item.refField.filterValue;
However at some point this stopped working - the reference field simply contains the _id from the referenced table as a string.
So I thought I should be able to use the wix-data API to query the referenced table - but I cannot get this to work at all - my data.js:
import wixData from 'wix-data';
export function BusinessDirectory_beforeUpdate(item, context) {
//TODO: write your code here...
wixData.query("AdType")
.find()
.then( (results) => {
item.filterBusinessType = JSON.stringify(results);
} )
.catch((err) => {
item.filterBusinessType = err;
});
item.displayTitle = item.title.toUpperCase();
}
If this was working I would expect something to end up in item.filterBusinessType however I get nothing and no error message either. The final line is invoked and works.
So now I’m stumped - how can I update data in the table using data from a referenced table…
Any ideas welcome!
Thank you!