Reputation: 15
I have two fields. One is 'Date Last Checked' the other is 'Date Due'. I need the 'Date due' to automatically be 364 days ahead of the 'Date Last Checked'
Upvotes: 1
Views: 915
Reputation: 6347
Basically it comes down to this question: Add days to JavaScript Date
...however it has some App Maker specificity. It seems that the right way to implement it from the Security standpoint will be using onBeforeCreate
and onBeforeSave
Model Events and Server Side script to enforce data consistency:
// Define this function somewhere in server scripts
function addDays(date, days) {
var result = new Date(date);
result.setDate(result.getDate() + days);
return result;
}
// onBeforeCreate event handler
record.DueDate = addDays(record.LastChecked, 364);
// onBeforeSave event handler (to keep things simple we can
// update DueDate when any of record's fields is changed)
record.DueDate = addDays(record.LastChecked, 364);
Other benefits of this approach
Upvotes: 1