Methods of the Helper Object
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 ticket. 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 ticket. 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 ticket. Example:
Changing the routing
The functions described in this section will provide the changing of the addressing of tickets in todo4teams. So you could, for example, change the addressing incoming mail or SMS depending on the time of day either team X or team Y.
This function can be used to address the current ticket to any team. The transfer parameter is the unique ID of the team. The ticket is sent as 'new' to the addressed team. A copy of the ticket with the current owner is stored in the database and is associated with the history of forwarded tickets. Example:
A "convenience" function that performs a call of the above mentioned function. It determines previously the ID that is used with the team name. If the name is not unique the ID of the first detected team is used. Example:
This function allows the current ticket 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 ticket. 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 ticket.
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 teams
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 teams 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 ticket can be processed.
This function shows all attachments within your current ticket.
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 ticket.
Example of removing all attachments from an incoming email:
This function deletes all attachments named "attachmentname" of the current ticket.
Example of removing the file attachment named Formular.pdf:
Working with strings
This function returns the estimated languageof the String „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 ...
Extracts the list of hits from the string "input" using the regular expression "rexExp". The parameter multiMatch specifies whether it should evaluate all hits in depth.
In this example, an HTML file attachment is read in as a string and broken down using a regular expression. The HTML code contains a table in which the first column contains names and the second column contains values. The variables label and value take on the respective values in the loop.
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];
// ...
}
This function creates a string from the byte sequence “bytes”. The “charSetName” parameter specifies the character set of the string to be created.
Beispiel: Umwandlung eines Byte-Arrays in einen String
Working with PDF attachments
These functions can be used to edit PDF attachments in the current ticket. A helper class used here is the PdfFormField class. Describes the triple of field name, field value and field type for a field of a PDF form.
String name;
String value;
String ftype;
}
PdfFormField[] getPdfFormFields(TodoAttachment pdfAttachment)
This function returns the list of all form fields for the passed PDF attachment.
Example: Reading the PDF form fields from a PDF file
var attachment = helper.attachments[ai];
println("Name: "+attachment.attachmentName);
if(attachment.attachmentName=="Formular.pdf"){
var fields = helper.getPdfFormFields(attachment);
}
}
Function for automatic form generation of forms. This can be used to automatically generate the form corresponding to a PDF form.
Example: Automatic generation of a form from a PDF form
var attachment = helper.attachments[ai];
println("Name: "+attachment.attachmentName);
if(attachment.attachmentName=="Formular.pdf"){
helper.createFormFromPdfAttachment(attachment);
}
}
Generate new jobs
available for
☑ SMS scripts
☑ Email scripts
☑ Start action
☑ End action
The function
int addressedGroupId,
String title,
String description,
int minutes,
int ownerId,
Map<Long, Map<String, Object>> forms,
List<ToDoAttachment> attachments)
enables the creation of new tickets within a script execution. The ID of the generated ticket is returned as a result.
In the following example, a ticket with an attached form and file attachment is sent to the group with ID 17.
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
available for
☑ Send action
☑ Accept action
☑ Complete action
The functions in this section are used to display messages from a script. This is particularly useful for the completion scripts of forms. These scripts can be used to carry out consistency checks in todo4teams before a ticket is closed. If these fail, for example, this can be signaled using these functions.
Example: Displaying an error message.
helper.errorMessage(„Es ist ein Fehler aufgetreten!“);
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
This function returns the presumed language based on the passed string "input". The environment variable coretext is also provided in the email inbox to simplify language analysis. It is ideally used to identify the language of an email.
Example of querying the language of an incoming email. The variable coretext is filled with the text content of the email.
if(lang==“german“){
// …
} else ...
Extracts the list of hits from the string "input" using the regular expression "rexExp". The parameter multiMatch specifies whether it should evaluate all hits in depth.
In this example, an HTML file attachment is read in as a string and broken down using a regular expression. The HTML code contains a table in which the first column contains names and the second column contains values. The variables label and value take on the respective values in the loop.
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];
// ...
}
This function creates a string from the byte sequence “bytes”. The “charSetName” parameter specifies the character set of the string to be created.
Example: Converting a byte array to a string
Working with PDF attachments
These functions can be used to edit PDF attachments to the current ticket. A helper class used here is the PdfFormField class. Describes the triple of field name, field value and field type for a field of a PDF form.
String name;
String value;
String ftype;
}
PdfFormField[] getPdfFormFields(TodoAttachment pdfAttachment)
This function returns the list of all form fields for the passed PDF attachment.
Example: Reading the PDF form fields from a PDF file
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
available for
☑ SMS scripts
☑ Email scripts
☑ Start action
☑ End action
The function
int addressedGroupId,
String title,
String description,
int minutes,
int ownerId,
Map<Long, Map<String, Object>> forms,
List<ToDoAttachment> attachments)
enables the creation of new tickets within a script execution. The ID of the generated ticket is returned as a result.
In the following example, a ticket with an attached form and file attachment is sent to the group with ID 17.
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
available for
☑ Send action
☑ Accept action
☑ Complete action
The functions in this section are used to display messages from a script. This is particularly useful for the completion scripts of forms. These scripts can be used to run consistency checks in todo4teams before a ticket is closed. If these fail, this can be signaled using these functions.
Example: Displaying an error message.
Example: Displaying a warning
Displaying an informational message.
Example: Displaying a message
Status of execution
This is a convenience function that provides information about whether a script was executed successfully.