I was trying to pull out month & date and compare to current date and if its equal trigger an email
I am not sure I set this up right any suggestions would be helpful
- There’s a syntax error in the json in job.config.
a comma is missing after the description property value. - the public file contains $w and you can’t have it there (only on a front-end page file). It’s also never relevant to scheduled jobs (which has no access the any page UI).
- I don’t understand what you’re trying to achieve.
i am trying to trigger an email from my content collection on birthdate
So have the function on a backend file. something like:
//backend/birtdhay-message.js
import wixData from 'wix-data';
export function sendBirthdayMessages(){
const now = new Date();
return wixData.query('MembersCollectionName')
.eq('monthNumber', now.getMonth())//adjust it to timezone
.eq('day', now.getDate())//adjust it to timezone
.limit(1000)
.find()
.then(r => {
const members = r.items;
if(!members.length){
return Promise.reject('no_members_found');
}
//here extract the email address from the members array and send it to the members
})
}
And adjust the function path and name in jobs.config (+ don’t forget fix the comma issue)
will try thanks
so the query is not pulling any data, the data was stored as “August 8, 1978” using DatePicker so i added code to compare that
let mon = now . getMonth (); //storing the month number in variable mon
const month = [ “January” , “February” , “March” , “April” , “May” , “June” , “July” , “August” , “September” , “October” , “November” , “December” ];
let name = month [ now . getMonth ()]; //pulling the month spelled out based on month number, storing in name variable
eq ( ‘birthday’ , name )
. eq ( ‘birthday’ , now . getDate ())
should i have two addl fields in the database seperating month and day?
so it dawned on me that the date picker was not needed so i ditched it and decided to use a regular text box to store the date utilizing this code I was able to get the results i wanted:
const now = new Date(); //storing current date in now variable in correct time zone
const mon = “0” + (now.getMonth() + 1); //storing the month number in variable mon as type Date
const day = now.getDate();
**let** strday = day.toString();
**let** strmon = mon.toString();
wixData.query('PhoneBook')//name of collection to query
.startsWith('birthDate', strmon + '/' + strday)
now i am working on the email piece of things, i had to test this in the frontend because i couldnt see the console.logs , let me know if you have any thoughts on that