Methods of the Helper Object


Back to Auxiliary Scripting Objects in todo4teams...

To simplify the creation of scripts there is a helper object that is valid in the context of all the scripts. This auxiliary object is called "helper" in all scripts.

All functions listed here can throw exceptions, that react appropriately to error conditions. The administrator can decide in which function call he wants to catch the potential exceptions.

Working with forms

The following functions are suitable to work with forms in todo4teams.

TodoTaskExtendedMetaData addMetaData(long metaDataId)

This function can be appended to the forms of the current job. You may ie use  this feature If you want to automatically add a form to a mailbox on the arrival of emails.
The return value is the form attached to the job. Example:

var formular=helper.addMetaData(7);
TodoTaskExtendedMetaData addMetaDataByName(String metaDataName)

This is a "convenience" function that make a call using the above function. Previously it determines the ID to be used within the form name. If the name is not unique, the ID of the first identified form is taken.
The return value is the form attached to the job. Example:

var formular=helper.addMetaDataByName('Kundendaten');
void addValueForField(TodoTaskExtendedMetaData md, String name, Object value)

With this function the values can be set into a form. The first parameter md is the respective form. The second parameter is the name of the field and the third parameter is the value to be set.
This feature is e.g. useful when values have to be included automatically into a form from an pdf-form that was attached to an email.

TodoTaskExtendedMetaData[] getTaskMetaData()

Returns all the forms of the current job. Example:

var alleFormulare=helper.getTaskMetaData();

Changing the routing

The functions described in this section will provide the changing of the addressing of jobs in todo4teams. So you could, for example, change the addressing incoming mail or SMS depending on the time of day either group X or group Y.

void routeToGroup(long groupId)

This function can be used to address the current job to any group or skill. The transfer parameter is the unique ID of the group. The job is sent as 'new' to the addressed group. A copy of the job with the current owner is stored in the database and is associated with the history of forwarded jobs. Example:

helper.routeToGroup(23);
void routeToGroupByName(String groupName)

A "convenience" function that performs  a call of the above mentioned function. It determines previously the ID that is used with the group name. If the name is not unique the ID of the first detected group is used. Example:

helper.routeToGroupByName('Software-Service');
void routeToUser(long userId)

This function allows the current job to be addressed firmly to a specific todo user. The transfer parameter is the unique ID of the user. The function should be used sparingly, since it contradicts the principle of the marketplace of todo4teams. Example:

helper.routeToUser(99);
void routeToUserByUsername(String userName)

A "convenience" function that performs  a call of the above mentioned function. It determines perviously the ID that is used with the user name. If the name is not unique the ID of the first detected user is used. Note that the username (that is, the logon ID) should be chosen - not the real name. Example:

helper.routeToUserByUsername('max.muster');
void setOwner(long userId)

This function allows the selection of the owner of a job. The transfer parameter is the unique ID of the owner. Example:

helper.setOwner(27);
void setOwnerByUsername(String userName)

A "convenience" function that performs  a call of the above mentioned function. It determines perviously the ID that is used with the user name. If the name is not unique the ID of the first detected user is used. Example:

helper.setOwnerByUsername('max.muster');

Changing of the target time

The following functions are used to change the target time of the current job.

void addSecondsToScheduledEndDate(int seconds)

With this function seconds are added to the target time. Example:

helper.addSecondsToScheduledEndDate(600);
void setDateForScheduledEndDate(int year, int month, int day, int hour, int minute, int second)

With this function the date and the time of day are determined and given as the transfer parameters to the target time for the current. Example

helper.setDateForSchedukedEndDate(2010,12,31,10,0,0);

Access to users and groups/skills

TodoUser[] getUser()

Shows all registered users within your current instance of todo4teams. Example:

var users = helper.getUser();
var i;
for(i=0; i<users.length; i++){
 println(users[i].username);   
}
TodoWorkGroup[] getWorkGroups()

This function shows all registered groups and skills within your current instance of todo4teams.

var groups = helper.getWorkGroups();

var i
for(i=0; i<groups.length; i++){
 println(groups[i].name);      
}

Working with attachments

With the following function of the attachments of a todo4teams job can be processed.

TodoAttachment[] getAttachments()

This function shows all attachments within your current job.

Example of finding a file attachment with the name Formular.pdf.:

for(ai=0;ai<helper.attachments.length;ai++){

var attachment = helper.attachments[ai];

println("Name: "+attachment.attachmentName);

if(attachment.attachmentName=="Formular.pdf"){

//...

}

}
void removeAllAttachments()

This function removes all attachments of the current Todo job.

Example of removing all attachments from an incoming email:

helper.removeAllAttachments();
 
void removeAttachment(String attachmentname)

This function deletes all attachments named "attachmentname" of the current Todo job.

Example of removing the file attachment named Formular.pdf:

helper.removeAttachments(Formular.pdf);

Working with strings

Diese Funktion liefert die mutmaßliche Sprache als Rückgabewert auf Basis des übergebenen Strings „input“. Im E-Mail-Eingang wird zur vereinfachten Analyse der Sprache noch die Umgebungsvariable coretext bereitgestellt. Sie wird idealerweise verwendet um die Sprache einer E-Mail zu erkennen.

String getLanguage(String input)
Beispiel für Abfrage der Sprache einer eingehenden E-Mail. Die variable coretext ist mit dem Textinhalt der E-Mail belegt.
var lang = helper.getLanguage(coretext)
if(lang==german){
//
} else ...
Object extractByRegExp(String input, String regExp, boolean multiMatch)

Extrahiert aus dem String „input“ über den regulären Ausdruck „rexExp“ die Trefferliste. Der Parameter multiMatch gibt an, ob er alle Treffer tief auswerten soll.

In diesem Beipiel wird ein HTML-Dateianhang als String eingelesen und mit einem regulären Ausdruck zerlegt. Der HTML-Code enthält eine Tabelle, in der in der ersten Spalte Namen und in der zweiten Spalte Werte stehen. Die Variablen label und value nehmen in der Schleife die jeweiligen Werte an.

// ...

var content = new
java.lang.String(attachment.attachmentContent, "UTF-8");

var fields =
helper.extractByRegExp(content,

"<tr><td>(.+?)</td><td><b>(.+?)</b></td></tr>",

true);

for(j=0;j<fields.length;j++){

try{

     var label = fields[j][0];

     var value = fields[j][1];

// ...

}
String bytesToString(byte[] bytes, String charSetName)

Diese Funktion erstellt aus der Bytefolge „bytes“ einen String. Über den Parameter „charSetName“ wird der Zeichensatz des zu erstellenden Strings festgelegt.

Beispiel: Umwandlung eines Byte-Arrays in einen String

Var s = helper.bytesToString(byteArray, UTF-8);

Working with PDF attachments

Mit diesen Funktionen können PDF-Anhänge am aktuellen Job bearbeitetet werden. Eine hier benutzte Hilfsklasse ist die Klasse PdfFormField. Beschreibt das Triple aus Feldname, Feldwert und Feldtyp zu einem Feld eines PDF-Formulars.

class PdfFormField {

String name;

String value;

String ftype;

}

PdfFormField[] getPdfFormFields(TodoAttachment pdfAttachment)

Diese Funktion liefert zum übergebenen PDF-Anhang noch die Liste aller Formularfelder .

Beispiel: Auslesen der PDF-Formularfelder aus einer PDF-Datei

for(ai=0;ai<helper.attachments.length;ai++){

var attachment = helper.attachments[ai];

println("Name: "+attachment.attachmentName);

if(attachment.attachmentName=="Formular.pdf"){

var fields = helper.getPdfFormFields(attachment);

}

}
void createFormFromPdfAttachment(TodoAttachment pdfAttachment, String formName)

Funktion zur automatische Formulargenerierung von Todo-Formularen. Hiermit kann automatisch das zu einem PDF-Formular korrespondierende Todo-Formular erzeugt werden.

Beispiel: Automatische Erzeugung eines Todo-Formulars aus einem PDF-Formular

for(ai=0;ai<helper.attachments.length;ai++){

var attachment = helper.attachments[ai];

println("Name: "+attachment.attachmentName);

if(attachment.attachmentName=="Formular.pdf"){

helper.createFormFromPdfAttachment(attachment);

}

}

Generate new jobs

verfügbar für
☑ SMS-Skripte
☑ E-Mail-Skripte
☑ Start-Aktion
☑ End-Aktion

Die Funktion

long createTask(
int addressedGroupId,
String title,
String description,
int minutes,
int ownerId,
Map<Long, Map<String, Object>> forms,
List<ToDoAttachment> attachments)

ermöglicht die Erzeugung neuer Jobs innerhalb einer Skriptausführung. Die ID des erzeugten Jobs wird als Ergebnis zurückgegeben.

Im folgenden Beispiel wird ein Job mit angehäntem Formular und Dateianhang an die Gruppe mit der ID 17 gesendet.

var forms = new
 java.util.HashMap();

var values = new
 java.util.HashMap();

values.put(new
 java.lang.String("Name_t"), new
 java.lang.String("Bergener"));

values.put(new
 java.lang.String("Vorname_t"), new
 java.lang.String("Thomas"));

forms.put(new
 java.lang.Long(41), values);

var attachments = new
 java.util.ArrayList();

var att1 = new
 com.proxemo.todo.bom.ToDoAttachment();


att1.setAttachmentName("test1.txt");

att1.setAttachmentContent(new
 java.lang.String("some file content").getBytes());


attachments.add(att1);


var minutes = 20;

var toGroup = 17;

var owner = 0;

var id = helper.createTask(toGroup, "Create!","Just do it!", minutes, owner, forms,attachments);

Display messages

verfügbar für
☑ Absenden-Aktion
☑ Übernahme-Aktion
☑ Erledigen-Aktion

Die Funktionen dieses Abschnitts dienen der Anzeige von Nachrichten aus einem Skript heraus. Dies ist insbesondere für die Erledigen-Skripte von Formularen hilfreich. Über diese Skripte können in todo4teams vor dem Abschluss eines Jobs Konsistenzprüfungen ausgeführt werden. Schlagen diese z.B. fehl, so kann dies mit diesen Funktionen signalisiert werden.

void errorMessage(String message)

Beispiel: Anzeige einer Fehlernachricht.

helper.errorMessage(Es ist ein Fehler aufgetreten!);
void warningMessage(String message)

Beispiel: Anzeige einer Warnung

helper.warningMessage(Sie haben keinen Adressaten angegeben!);
void infoMessage(String message)

Anzeige einer Informationsnachricht.

Beispiel: Anzeigen einer Nachricht

helper.infoMessage (Vielen Dank!);

Status of execution

static boolean executionWasSuccessfull(String result)

Dies ist eine „Convenience“-Funktion, die Auskunft darüber gibt, ob ein Skript erfolgreich ausgeführt wurde.

Weiter zu  Die Methoden des Message-Objektes...

 

     

Child Pages