Bulletins


In this tutorial, we describe how you can easily send scheduled bulletin emails using a 'scheduled script', for example, to report simple statistics from the previous day or the number of logged-in agents daily.

The code shown below automatically generates a daily email report in this format:

image-20250918115444-1.png

To do this, create a 'scheduled script' in this format...

image-20250918114504-2.png

...and insert the code below as script code.

Adjust the list of team IDs and the email recipient's address according to your needs and expand the report with your own analyses as desired.

var teamIDs = "110,21,23,51";
var toemail = "service-lead@mycompany.com";

var Calendar = Java.type("java.util.Calendar");

function getEndOfYesterday() {
   var calendar = Calendar.getInstance();
   calendar.setLenient(true);
   var year = calendar.get(Calendar.YEAR);
   var month = calendar.get(Calendar.MONTH);
   var day = calendar.get(Calendar.DATE);
   calendar.set(year, month, day, 23, 59, 59);
   calendar.add(Calendar.DAY_OF_MONTH, -1);
   return calendar.getTime();
}

function getStartOfYesterday() {
   var calendar = Calendar.getInstance();
   
   calendar.setLenient(true);
   var year = calendar.get(Calendar.YEAR);
   var month = calendar.get(Calendar.MONTH);
   var day = calendar.get(Calendar.DATE);
   calendar.set(year, month, day, 0, 0, 0);
   calendar.add(Calendar.DAY_OF_MONTH, -1);
   return calendar.getTime();
}

var d1 = getStartOfYesterday();
var d2 = getEndOfYesterday();

var tx = helper.getComponentStore().query("select t.addressedWorkgroup.name, t.addressedWorkgroupId,  count(t) from ToDoTask t where t.addressedWorkgroupId in ("+teamIDs+") and t.active and t.state=3 and t.endDate BETWEEN ?1 and ?2 group by t.addressedWorkgroupId, t.addressedWorkgroup.name", d1,d2);

htmlText="<html><head>";
htmlText+="<style>.stattable td, .stattable th { padding: 4px; text-align: left; border: 1px solid lightgrey; }";
htmlText+=".stattable th { background-color: #def5fb;}";
htmlText+=".stattable td { background-color: #f9f9f9;}";
htmlText+=".stattable {border-collapse: collapse;}";
htmlText+="</style>"
htmlText+="</head><body>";
htmlText+="<h2>Daily Service Bulletin</h2>";
htmlText+="<p>Tickets solved yesterday:</p>";
htmlText+="<table class='stattable' style='min-width: 400px;'><tr><th>Team</th><th>Tickets Solved</th></tr>";
for each (var t in tx){
   println(t[0]+ " / "+ t[1] + " / "+ t[2]);
   htmlText+="<tr><td>"+t[0]+"</td><td>"+t[2]+"</td></tr>";
}
htmlText+="</table>";



htmlText+="<p>Agents currently online ("+new java.util.Date().toString()+"):</p>";
htmlText+="<table class='stattable' style='min-width: 400px;'><tr><th>Team</th><th>Agents Online</th></tr>";

var idArr=teamIDs.split(",");
for(var i=0; i<idArr.length; i++){
   var id=idArr[i];
   var team = com.proxemo.todo4.bom.caches.ToDoWorkGroupCache.getInstance().getItemById(id)
   if(team!=null){
       htmlText+="<tr><td>"+team.name+"</td><td>"+com.proxemo.todo4.server.SessionManager.getInstance().numberOfMembersOnline(team.id)+"</td></tr>";
    }
}
htmlText+="</table>";

htmlText+="</body></html>";

helper.sendmail(2, "Daily Service Bulletin", htmlText, toemail, null, null, null, true);