Re-addressing tickets by script


By means of scripts  jobs can be assigned to other teams in an automated manner depending on various parameters.

This can be particularly useful if tickets are not completed after a certain processing time and is to be passed on to another team as a process of escalation.

The following example shows the basic procedure, the initial situation is as follows:

Let us assume we want to check team #100 for tickets that are open for more than four weeks. Those tickets should be shifted to team #101 for escalation.

These tickets should be automatically queried overnight and assigned to the target team.

Select 'Script Scheduling' in the main menu and create a new scheduled script. Name it 'Re-Route' e.g.

To execute this script daily at 6 a.m. set '0 0 6 * * ?*' as the cron pattern.

image-20241217141105-1.png

Select the 'Script' tab and insert the code shown below.

image-20241217141506-2.png

Check the code an note that the two team ids (#100 and #101) are set in first lines.

The codes prepares and executes an archive query and iterates the result.

Every ticket found is than loaded (refreshed) from the databases, addressed to the new team #101 and processed as 'updated' by calling the action 'ToDoUpdateSimpleTaskAction':


var qm =  helper.getInstanceForClass("com.proxemo.todo4.bom.ToDoArchiveQueryMap");

var fromGroup = helper.getWorkgroupById(100);
var toGroup = helper.getWorkgroupById(101);


qm.setAddressedWorkgroup(fromGroup);

// Move tickets in state 0 (=open) only:
qmstate= new java.lang.Integer(0);

// Move tickets older than 4 weeks and newer than 8 weeks (to limit result set):
var d0 = new java.util.Date(java.lang.System.currentTimeMillis()-8*7*24*3600*1000); // 8 weeks
var d1 = new java.util.Date(java.lang.System.currentTimeMillis()-4*7*24*3600*1000); // 4 weeks
qm.setCreationDateRange(d0,d1);
// perform the archive query:
var qaction = helper.getInstanceForClass("com.proxemo.todo4.server.action.ToDoQueryArchiveAction");
var qresult = qaction.execute(-1, qm);
if(qresult!=null && qresult.size()!=null){
println("number of tasks to move: "+qresult.size());
if (qresult.size()>0){
   for(var i =0; i<qresult.size(); i++){
      println("Re-route task "+qresult.get(i).getId());
     var t = qresult.get(i);
      t= helper.getComponentStore().find(t.getClass(), t.getId());
      t.getAddressee().setAddressedWorkgroup(toGroup);
     var aaction = helper.getInstanceForClass("com.proxemo.todo4.server.action.ToDoUpdateSimpleTaskAction");
     var ts = new com.proxemo.todo4.bom.ToDoTaskShell(t);
      aaction.execute(-1, ts);
    }
}
} else {
    println("Error anonymizing tickets: No result or empty.");
}