weekly open work-item emails

Description
moem1
Posts: 36
Joined: Wed Feb 23, 2011 4:27 pm

weekly open work-item emails

Postby moem1 » Wed Sep 07, 2011 4:15 pm

Hi,

I thought I'd post what I did to create a weekly reminder emails about open work-items. If there was a much easier way to do this, then please let me know as I couldn't find one that worked for my server setup. My JavaScript is a bit rusty, but this was a nice exercise for myself. Feel free to suggest improvements.

Using the Scripting POP Extension, I created a Scheduler entry for my "weekly_open_work-items_email.js" script (which is stored under /opt/alm/polarion/scripts on my Linux server. The code is below and is somewhat specific to my company but may be adapted to yours.

Regards,

- Mark


Code: Select all

// // // Polarion Weekly Notificaiton About Open Work-Items // // //
importPackage(java.io);
importPackage(java.lang);

// // defaults // //
var sQuery      = "ALL:ALL_VALUE";
var sServer     = "http://cad/polarion";
var sAdminEmail = "cad@medtronic.com";
// list of status to be considered "Closed"
var hClosed = {};
hClosed["Closed"] = 1;

// // gather all open work-items // //
// hash to store notification work-items by userid
var hNotify = {};
// query for all not Closed work-items
var openWIs = trackerService.queryWorkItems(sQuery, "id");
// iterate on open work-items
var iLen = openWIs.size();
for (var i=0; i< iLen; i++) {
  var wi = openWIs.get(i);
  var sWorkitemId = wi.getId();
  var sStatus = wi.getStatus().getName();
  // skip over work-items that are considered "Closed"
  if (typeof hClosed[sStatus] != "undefined") {continue}
  var sProject = wi.getProject().getId();
  var sAuthorId = wi.getAuthor().getId();
  var sAuthorName; try {sAuthorName=wi.getAuthor().getName()} catch (err) {sAuthorName=sAuthorId}
  var aAssignees= [];
  // get list of Assignees
  for (j=wi.getAssignees().iterator(); j.hasNext();) {
    var u = j.next();
    var sAssigneeId = u.getId();
    aAssignees.push(sAssigneeId);
    if (typeof hNotify[sAssigneeId] == "undefined") {hNotify[sAssigneeId] = []}
    hNotify[sAssigneeId].push(sProject + "/" + sWorkitemId);
  }
  // any Assignees?
  if (aAssignees.length < 1) {
    // no Assignees, notify Author instead
    if (typeof hNotify[sAuthorId] == "undefined") {hNotify[sAuthorId] = []}
    hNotify[sAuthorId].push(sProject + "/" + sWorkitemId);
  }
}

// // send emails // //
for (var sUserid in hNotify) {
  var user = projectService.getUser(sUserid);
  // default email to get notice if user email not defined
  var sEmail = ""; try {sEmail=user.getEmail()} catch (err) {sUserName=sAdminEmail}
  // debug // sEmail = sAdminEmail;
  // get user name
  var sUserName = ""; try {sUserName=user.getName()} catch (err) {sUserName=sUserid}
  // create email process
  var aCommand = ["/usr/lib/sendmail", sEmail];
  var process = Runtime.getRuntime().exec(aCommand);
  var stdin  = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
  stdin.write("Mime-Version: 1.0\n");
  stdin.write("Content-type: text/html; chareset=\"iso-8859-1\"\n");
  stdin.write("From: polarion@domain.invalid\n");
  stdin.write("To: " + sEmail + "\n");
  stdin.write("Subject: Polairon Open Work-Items for " + sUserName + "\n");
  stdin.write("<HTML><HEAD><TITLE>Polarion Open Work-Items for " + sUserid + "</TITLE></HEAD><BODY>\n");
  stdin.write("This is a reminder that the following work-items are waiting for userid " + sUserid + " in Polarion.  Click on an ID below to review the work-item.<BR><BR>\n");
  stdin.write("<TABLE border=2>\n");
  stdin.write("<TR><TH>Project</TH><TH>ID</TH><TH>Status</TH><TH>Author</TH><TH>Assignees</TH><TH>Updated</TH><TH>Title</TH></TR>\n");
  // loop through all work-items for this user
  // logger.info("hNotify[" + sUserid + "] typeof " + typeof hNotify[sUserid] + " is " + hNotify[sUserid]);
  for (var i in hNotify[sUserid]) {
    // logger.info("hNotify[" + sUserid + "][" + i + "] typeof " + typeof hNotify[sUserid][i] + " is " + hNotify[sUserid][i]);
    var sWi = hNotify[sUserid][i];
    var aWi = sWi.split("/", 2);
    var sProject = aWi[0];
    var sWorkitemId = aWi[1];
    var wi = trackerService.getWorkItem(sProject, sWorkitemId);
    var sAuthorId = wi.getAuthor().getId();
    var sAuthorName; try {sAuthorName=wi.getAuthor().getName()} catch (err) {sAuthorName=sAuthorId}
    var aAssignees= [];
    // get list of Assignees
    for (j=wi.getAssignees().iterator(); j.hasNext();) {
      var u = j.next();
      var sAssigneeId = u.getId();
      var sAssigneeName; try {sAssigneeName=u.getName()} catch (err) {sName=sAssigneeId}
      aAssignees.push(sAssigneeName);
    }
    var sAssigneeNames = aAssignees.join(", ");
   
    stdin.write(
      "<TR><TD>" + sProject + "</TD>" +
      "<TD><A HREF='" + sServer + "/#/project/" + sProject + "/workitem?id=" + sWorkitemId + "'>" + sWorkitemId + "</A></TD>" +
      "<TD>" + wi.getStatus().getName() + "</TD>" +
      "<TD>" + sAuthorName + "</TD>" +
      "<TD>" + sAssigneeNames + "</TD>" +
      "<TD>" + wi.getUpdated() + "</TD>" +
      "<TD>" + wi.getTitle() + "</TD></TR>\n"
    );
  }
  stdin.write("</TABLE>\n");
  stdin.write("</BODY></HTML>\n");
  stdin.close(); 
}

// var sAssigneeNames = aAssignees.join(", ");
// logger.info("ID=" + wi.getId() + " Type=" + wi.getType().getName() + " Status=" + wi.getStatus().getName() + " Assignee=" +  sAssigneeNames + " Author=" + sAuthorName + " Updated=" + wi.getUpdated() + " Title=" + wi.getTitle() );


NickEntin
Posts: 472
Joined: Tue Oct 24, 2006 10:27 am
Location: Polarion Software GmbH, Stuttgart
Contact:

Re: weekly open work-item emails

Postby NickEntin » Wed Sep 14, 2011 11:38 am

Hi Mark,

as a quick feedback - you can easily post your script as submission to the POP site. There people find it easier than in the forum.

Just follow the link http://extensions.polarion.com/polarion/extensions/submissions.jsp (you can find it also on the home page of the POP site)

We really appreciate community contribution, which could be useful for others

Best regards,
Nick


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 12 guests