@mailsends in an @for loop

Hello beautiful people. Have a rookie question that has me banging my head against the wall. Trying to loop a mail send using formula language and not getting it to work. Here’s the situation:

I have to send reminder emails to supervisors whose employees haven’t filed time sheets for the last pay period; one email to each supervisor with a list of the employees. I already have a handle on StartingDate, which is a text value. Here’s my code:

{This gets me a list of the supervisors who have employees who haven’t filed a time sheet. This works perfectly.}

sups:=@Unique(@DbLookup(“”; “”; “LUPinkSheetStatus”; StartingDate; 2));

{This gets me a list of the employees who haven’t filed a time sheet, but returns ALL employees, not one for each supervisor:}

emps:=@Unique(@DbLookup(“”; “”; “LUPinkSheetStatus2”; StartingDate+sups; 2));

{Finally, this is the code that I was hoping would send an email to each supervisor with a list of just that supervisor’s employees, but doesn’t do a thing:}

Total:=@elements(sups);

@For(Counter:=1;

Counter<=Total;

Counter:=Counter+1;

emailaddr:=sups[i];

@MailSend(emailaddr;“”;“”;“Employees who haven’t filed a time sheet for the period starting on “+StartingDate;””;@Implode(emps;@newline))

I’m thinking the employee list needs to be in a loop, too, but I can’t get far. Any advice would be very much appreciated!

Subject: @mailsends in an @for loop

I can’t see where you’ve set i, so shouldn’t this lineemailaddr:=sups[i];

be

emailaddr:=sups[Counter];

You’re right that this line will need to be within the loop

emps:=@Unique(@DbLookup(“”; “”; “LUPinkSheetStatus2”; StartingDate+sups; 2));

Try

emps:=@Unique(@DbLookup(“”; “”; “LUPinkSheetStatus2”; StartingDate+sups[Counter]; 2));

Subject: RE: @mailsends in an @for loop

You are my hero, Matt! Here’s the final code working exactly as it should. THANKS!!

sups:=@Unique(@DbLookup(“”; “”; “LUPinkSheetStatus”; StartingDate; 2));

runday:=@Adjust(@Date(@TextToTime(EndingDate));0;0;3;0;0;0)

Total:=@Elements(sups);

@For(Counter:=1;

Counter<=Total;

Counter:=Counter+1;

emailaddr:=sups[Counter];

emps:=@Unique(@DbLookup(“”; “”; “LUPinkSheetStatus2”; StartingDate+sups[Counter]; 2));

@If(@Today!=runday;@Return(“”);@MailSend(emailaddr;“”;“”; “Time sheets missingFor One or More Employees “;””;"Good morning. One or more of your direct reports’s weekly time sheets have not yet been approved for for the pay period. Employees whose time sheets still requiring processing are: "+@newline+@newline+ @Implode(emps;@NewLine))))