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.
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:
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:
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.
Returns all the forms of the current job. Example:
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.
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:
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:
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:
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:
This function allows the selection of the owner of a job. The transfer parameter is the unique ID of the owner. Example:
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:
Changing of the target time
The following functions are used to change the target time of the current job.
With this function seconds are added to the target time. Example:
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
Access to users and groups/skills
Shows all registered users within your current instance of todo4teams. Example:
var i;
for(i=0; i<users.length; i++){
println(users[i].username);
}
This function shows all registered groups and skills within your current instance of todo4teams.
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.
This function shows all attachments within your current job.
Example of finding a file attachment with the name Formular.pdf.:
var attachment = helper.attachments[ai];
println("Name: "+attachment.attachmentName);
if(attachment.attachmentName=="Formular.pdf"){
//...
}
}
This function removes all attachments of the current Todo job.
Example of removing all attachments from an incoming email:
This function deletes all attachments named "attachmentname" of the current Todo job.
Example of removing the file attachment named 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.
Beispiel für Abfrage der Sprache einer eingehenden E-Mail. Die variable coretext ist mit dem Textinhalt der E-Mail belegt.
if(lang==“german“){
// …
} else ...
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];
// ...
}
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
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.
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
var attachment = helper.attachments[ai];
println("Name: "+attachment.attachmentName);
if(attachment.attachmentName=="Formular.pdf"){
var fields = helper.getPdfFormFields(attachment);
}
}
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
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
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.
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.
Beispiel: Anzeige einer Fehlernachricht.
Beispiel: Anzeige einer Warnung
Anzeige einer Informationsnachricht.
Beispiel: Anzeigen einer Nachricht
Status of execution
Dies ist eine „Convenience“-Funktion, die Auskunft darüber gibt, ob ein Skript erfolgreich ausgeführt wurde.
Weiter zu Die Methoden des Message-Objektes...