Assignment Reminder Emails

For users who don't visit the application very often, it may be useful to send out a reminder email to them if they have outstanding assignments that need to be actioned.

You can do this by adding a couple of scripts to your application.

First, add a global action (go to the Application record for your app, click the hamburger and select "Actions", then click "+"). Call the action Send My Reminders. In the script, put this:

// get this user's assignments and send them out in an email
var #list = workflow:GetAssignments()
var #woList = NewList()
var #serviceList = NewList()
var #incidentList = NewList()
var #otherList = NewList()
loop through #list as #p
add #p to #otherList
end loop
var #toAdd = NewList()
add record ( Name="Assignments", List=#otherList) to #toAdd

var #ws = str:Trim(GetWebServerName(), "/")
if Count(#list)>0 then
var #lines = NewList()
var #body = ""
add "You have " + Count(#list) + " items in " + GetAppName() + " assigned to user '" + UserName() + "'.<p>" to #lines
loop through #toAdd as #a
if Exists(#a/List) then
add "<u>" + #a/Name + "</u><p>" to #lines
add "<ul>" to #lines
loop through #a/List as #app
add "<li>" to #lines
add "<a href='" + #ws + "/" + #app/URL + "'>" + #app/RelatedName + "</a>" to #lines
add "</li>" to #lines
end loop
add "</ul>" to #lines
end if
end loop
set #body = str:Join(#lines, "<p>", "")
call EMailUser(GetUser(), GetAppName() + ": " + Count(#list) + " items assigned to " + UserName(), #body, null)
end if

Next, go to the Application configuration again, click the hamburger and select "Scheduled Jobs". Add an entry in there, call it "Reminder Emails", and in the Preferred Time put 7am, or some time in the morning. In the Script part, put this:

elevate on
loop through load(&root/Users) as #user
[suppress errors] run task "SendMyAssignments" at &root with record () as #user
if Exists(#error) then
log "Reminders Job: " + #error
end if
end loop
log "Done sending reminders"

This will then send all users who have outstanding assignments an email each morning with a list of those assignments, and links to the relevant record.

You can modify the Scheduled Job script so that users have to sign-up for the reminders, by putting a filter on &root/Users. eg. instead it could say load(&root/Users[SendReminders=True]) and you'll need to add a Boolean field called Send Reminders to the Users tab. Once you do that, they must set that to Yes on their own user record in order to get the reminder email each day.

Next Topic: Custom Counter Fields