Hi, i have a birthdate field in my doctype and i want to write a client script such that it shows me whose’s birthday is there tomorrow. (i have added a button in the list view to trigger this filter)
How can i do this?? Since the date of birth also has year, i cant see a way to use any of the “date” filters to achieve this. Any ideas??
I have done some workaround for now. I have added a DOB string field which automatically takes string value of the date of birth when the record is created and then applied filter for it.
onload: function(listview) {
listview.page.add_inner_button(__('Show Birthdays Tomorrow'), function() {
let today = new Date();
let tomorrow = new Date(today);
tomorrow.setDate(today.getDate() + 1);
let day = ("0" + tomorrow.getDate()).slice(-2); // Get day with leading zero
let month = ("0" + (tomorrow.getMonth() + 1)).slice(-2); // Get month with leading zero
// Create the filter string like "%MM-DD%"
let filter_string = `%${month}-${day}%`;
console.log(filter_string);
frappe.route_options = {
"dob_string": ["like", filter_string]
};
frappe.set_route("List", "Birthday", "List");
});
},
refresh: function(listview) {
if (listview.data.length === 0) {
frappe.msgprint(__('No birthdays tomorrow.'));
}
}