routing of jobs via javascript


Using a Javascript selected jobs can be assigned in an automated manner to another group with the aid of various parameters.
This can be especially useful if after a certain processing time a job is not finished and the job should be transferred to another group for further processing.

The following example shows the basic procedure, the situation is as follows:
There is a group "Job sharing-start" whose jobs that are open for more than four weeks and the jobs should to be passed to the group "job deployment target" for further tracking.
The query for the corresponding jobs should run automatically overnight and should assign these jobs to the target group.
For this purpose there is the establishment of a support group "Job sharing-batch" required whose sole function is an automated repetition to initiate an internal job that performs the reclassification of relevant jobs.. Here are the three groups:

sc1a.jpg

For this auxiliary group "Job sharing-batch" now a Javascript is implemented in the start-action which is carried out during the creation of a new job for this auxiliary group.

sc2.jpg

The script in detail:

var sendingMailbox="Bergener und Partner <jobrouter@bergener-partner.de>";
var targetEmail="support@bergener-partner.de";

// function to write error message and send mail in case of error
function treatError(message)
{
println(message);
helper.sendmail(sendingMailbox, "Fehler im Batch-Job: "+task.getId(),
 message,targetEmail, null, null, false);

}

function moveOverdueTasks(){
println("releaseParkedRequests");  
var qm =  new com.proxemo.todo.bom.ToDoArchiveQueryMap(100);

// get all tasks from group Jonweitergabe_start that are still open
var feedbackGroup = com.proxemo.todo.server.ToDoScheduledTaskDispatcher.getInstance().getReallyAllWorkGroups().get(new java.lang.Long(29));
qm.addNameValue(com.proxemo.todo.bom.ToDoArchiveQueryMap.SKILL_ATTRIBUTE, feedbackGroup);
qm.addNameValue(com.proxemo.todo.bom.ToDoArchiveQueryMap.STATE_ATTRIBUTE, com.proxemo.todo.bom.ToDoTask.STATE_OPEN);

   println(">>>>>>>>>>> task with creationdate older than 4 weeks ago");  
// task with creationdate older than 4 weeks ago
var nowDate = new java.util.Date();
var dv = java.lang.reflect.Array.newInstance(nowDate.getClass(), 2);
var now = nowDate.getTime();
var oneMonthInMillis=3600*1000*24*30;
var threeMonthsInMillis=oneMonthInMillis*3


dv[0]=new java.util.Date(now-threeMonthsInMillis);
dv[1]=new java.util.Date(now-oneMonthInMillis);
qm.addNameValue(com.proxemo.todo.bom.ToDoArchiveQueryMap.DATE_START_ATTRIBUTE, dv);

//execute query
println(">>>>>>>>>>> execute query");  
var qresult = new com.proxemo.todo.server.action.ToDoQueryArchiveAction().execute(-1, qm);

println("Overdue Jobs: "+qresult.getTasks().size());

for(var i=0; i<qresult.getTasks().size(); i++)
 {
 var t = qresult.getTasks().get(i);
 println("Found Overdue task"+t.getId());
 var overdueGroup = com.proxemo.todo.server.ToDoScheduledTaskDispatcher.getInstance().getReallyAllWorkGroups().get(new java.lang.Long(31));
 
 t.getAddressee().setAddressedWorkgroup(overdueGroup);
 var ts = new com.proxemo.todo.bom.ToDoTaskShell(t);
 new com.proxemo.todo.server.action.ToDoUpdateSimpleTaskAction().execute(-1, ts);
 }        
}
try
{
println("Reading Jobweitergabe jobs older than 4 weeks");

// detect and move overdue tasks
moveOverdueTasks();

// close current task
task.startWorking();
task.finishWorking(true);

println("Processing Jobweitergabe jobs older than 4 weeks finished");
}
catch (exc)
{
println("Exception in prodi"+ exc);
println("Exception in prodi"+ exc.stack);
treatError("JOBWEITERGABE_GENERIC_ERROR:"+task.getId());

}

This automated updating and relaying job will be created as a repetition for the group "Job sharing-batch", in the present case the procedure is carried out daily at 23.00 clock.
Alternatively, the reassignment can be triggered manually at any time simply by creating a new job for the group "Job sharing-batch".

sc3.jpg

The relevant, customizable parts of Java scripts now in detail:

In this part of the initial group the affected jobs are defined, ie in the present example the group "Job sharing-start" with their group ID "29".

// get all tasks from group Jonweitergabe_start that are still open
 var feedbackGroup = com.proxemo.todo.server.ToDoScheduledTaskDispatcher.getInstance().getReallyAllWorkGroups().get(new java.lang.Long(29));
 qm.addNameValue(com.proxemo.todo.bom.ToDoArchiveQueryMap.SKILL_ATTRIBUTE, feedbackGroup);
 qm.addNameValue(com.proxemo.todo.bom.ToDoArchiveQueryMap.STATE_ATTRIBUTE, com.proxemo.todo.bom.ToDoTask.STATE_OPEN);

In this part the affected jobs are assigned to the of the target group, ie in the present example, the group "job deployment target" with their group ID "31".
 This group is now the new owner of the jobs.

 var t = qresult.getTasks().get(i);
  println("Found Overdue task"+t.getId());
  var overdueGroup = com.proxemo.todo.server.ToDoScheduledTaskDispatcher.getInstance().getReallyAllWorkGroups().get(new java.lang.Long(31));

As a standard the time window is set to a frame of 30 days up to 90 days. This can also be adjusted individually by changing the time values in the following script fragment:

var nowDate = new java.util.Date();
var dv = java.lang.reflect.Array.newInstance(nowDate.getClass(), 2);
var now = nowDate.getTime();
var oneMonthInMillis=3600*1000*24*30;
var threeMonthsInMillis=oneMonthInMillis*3

In summary,  in this example jobs were selected on the server in respect of two defined criteria (open, creation date between 30 days and 90 days in the past) and the assignment of these jobs were transposed to another group. In principle this selection is not limited only to the date of creation, all database fields of the job can be used for the selection.

However, the implementation requires at least some advanced knowledge of Java and Javascript.
Should you therefore have a corresponding request, please contact our support under support@bergener-partner.de

     

Child Pages