Creating of previews via Javascript


In this tutorial we are going to present you a way to simplify the handling of the new jobs that have been generated by a received fax.

The received fax is previously forwarded to a defined email address, the content of the fax is usually converted into a pdf- or tiff-file and attached to the e-mail. The technical details may therefore vary depending on your used hardware and infrastructure.

This email generates a new job in todo4teams; a priori it is disadvantageous that in advance it can only be recognized that a fax has been received, the actual content of the fax can only be made visible by opening the attachments.

There is, however, the possibility of using a Javascript to create a preview image of the fax and display the preview directly into the job; the original attachments of course remain and are part of the newly created job.

An example of such a generated image preview of an attached file:

fax2.png

In the picture above a small part  is marked; by clicking on the blue arrow the generated preview image can be rotated for better viewing .

Now to the actual used Javascript:
This must be defined within the arrival-action of the corresponding mailbox within todo4teams.

The helper-object creates with the following procedure

helper.insertPDFPreviews(2);

the desired previews, the number can be parameterized by the value in parentheses: in the present case these are two images, so the first two pages of the fax.
In order to prevent spam email to be received with possibly executable files, the following part of the overall script will removed these:

 task.setAttachments(helper.getSecuredAttachments('Anhang mit ausführbaren Dateien entfernt!'));

Now the entire script, this can be used directly within the arrival-action of the mailbox.
Additionally there will be checked whether at least one pdf-file has been received, so that the further processing of the ticket may be done depending on the outcome of this inquiry:

helper.insertPDFPreviews(2);

task.setAttachments(helper.getSecuredAttachments('Anhang mit ausführbaren Dateien entfernt!'));

var hasPDF = false;
for(ai=0;ai<helper.attachments.length;ai++)
{
var attachment = helper.attachments[ai];
if(attachment.attachmentName.endsWith("pdf")){
     // do something...
     hasPDF=true;
    }
}
if(hasPDF){
 // do something depending on attached PDFs
}