Goal
Use App Maker to collect User Birthdays and display only the Birthdays this Month.
Issue
I have a data model, persons. In that model are two Datasources, the default persons and a second birthdaysThisMonth. The datasource query script in birthdaysThisMonth properly runs and returns only the birthdays this month from the persons model.
However, when I change a birthdate in the persons datasource, the birthdaysThisMonth datasource remains unchanged, e.g., the Query script in birthdaysThisMonth is not re-executed.
To change the birthdate, I select a new date from the date picker, and the new value is shown in a table. I am not using a submit button, I see the change when the date picker looses focus.
What I've Tried
This script is executed as a Query script in the birthdaysThisMonth datasource which is not set to Manual save mode. It returns the records I want.
function setBirthdays() {
var calcRecords = [];
var personsRecords = app.models.persons.newQuery().run();
for (i=0; i<personsRecords.length; i++) {
var id = app.models.persons.newQuery().filters.Id._equals = i;
if (personsRecords[i].birthdate.getMonth() == thisMonth()) {
var calcRecord = app.models.persons.newRecord();
calcRecord.emailSecondary = personsRecords[i].emailSecondary;
calcRecord.birthdate = personsRecords[I].birthdate;
calcRecord.Id = personsRecords[i].Id;
calcRecords.push(calcRecord);
}
}
return calcRecords;
}
Question
How do I re-execute the query script in birthdaysThisMonth when the data in persons has been updated. How do I trigger the query so it reevaluates the data in persons and filters accordingly.
Using Events and onAfterSave seems promising, but I haven't found an example of this.
BTW
I'd like this work to happen on the server side if possible.
thisMonth()is misguided. I'm starting to think I need the client's table widget to query the model each time it needs to display these filtered records, instead of poking the server to update birthdates on the backend. - Chadd