Well, looks like I can’t attach files anymore!
But, here is the code for each file as individual posts… first one is events.js
//*******************
import wixData from ‘wix-data’ ;
import { triggeredEmails } from ‘wix-crm-backend’
var temp01 , temp02 , action01 , action02 , dd00 , dd01 , dd02 , ddtemp , link01 , link02 , link03 , DailyBiteHeading , DailyBiteDetails
export async function FindSMART ( ) {
// Access E4_ACTIONS
// Find all open actions i.e. those that are not completed or voided
wixData . query ( “E4_ACTIONS” )
. ne ( “status” , “Completed” )
. ne ( “status” , “Void” )
. ascending ( “dueDate” )
. eq ( “responsible” , "*********@gmail.com" ) // Debugging filter to avoid sending emails to all members
. find ()
. then (( CurrentActions )=>{
let FoundRecord = CurrentActions . items [ 0 ]
let contactId = FoundRecord . _owner
ddtemp = FoundRecord . dueDate
dd00 = ddtemp . toDateString ()
link01 = “https://www.//" + FoundRecord . _id
console . log ( "events.js 42 Found " , CurrentActions . items . length , " current actions for user " , contactId )
if ( CurrentActions . items . length > 1 ){ temp01 = CurrentActions . items [ 1 ]; action01 = temp01 . action ; ddtemp = temp01 . dueDate ; dd01 = ddtemp . toDateString (); link02 = "https://www.//” + temp01 . _id }
else ( action01 = “NA” , link02 = “” )
if ( CurrentActions . items . length > 2 ){ temp02 = CurrentActions . items [ 2 ]; action02 = temp02 . action ; ddtemp = temp02 . dueDate ; dd02 = ddtemp . toDateString (); link03 = “https://www.******//” + temp02 . _id }
else ( action02 = “NA” , link03 = “” )
wixData . insert ( ‘TR003_ScheduledJobsTracking’ ,{ “currentActions” : CurrentActions . items . length , “Member ID” : contactId , “ActionOne” : FoundRecord . action + dd00 , “ActionTwo” : action01 + dd01 , “ActionThree” : action02 + dd02 })
console . log ( "events.js 51 Link01 " , link01 , " Link02 " , link02 , " Link03 " , link03 )
//Find a random daily bite and assign it to DailyHint
let BiteNum = Math . round ( Math . random () 60 + 1 )
console . log ( "51 DailyBite Number = " , BiteNum )
wixData . query ( “LIST_DAILY_HINTS” )
. eq ( ‘number’ , BiteNum )
. find ()
. then (( Bite )=>{
DailyBiteHeading = Bite . items [ 0 ]. dailyBite
DailyBiteDetails = Bite . items [ 0 ]. description
console . log ( "57 DailyBiteHeading = " , DailyBiteHeading , " DailyBiteDetails = " , DailyBiteDetails )
triggeredEmails . emailMember ( ‘SMARTstepReminder’ , contactId , {
variables : {
CountOpen : CurrentActions . items . length ,
SMARTstep01 : FoundRecord . action + " ::: DUE DATE => " + dd00 ,
SMARTstep02 : action01 + " ::: DUE DATE => " + dd01 ,
SMARTstep03 : action02 + " ::: DUE DATE => " + dd02 ,
Link01 : link01 ,
Link02 : link02 ,
Link03 : link03 ,
DailyHintHeading : DailyBiteHeading ,
DailyHintDescription : DailyBiteDetails ,
}
})
. then ( ( success ) => {
console . log ( “events.js 73 Triggered email sent” );
} )
. catch ( ( err ) => {
console . log ( "events.js 76 " , err );
} );
return ( CurrentActions . items . length )
})
})
. catch (( err )=>{ console . log ( err )})
}