Pass data from a pdf as an e-mail attachment into a form


In both of the predecessing examples for dealing with pdfs we had already considered the following cases:

  • On the basis of an already existing pdf a form in todo has to be generated; here the field names should be reconciled in the two forms or be translated from into the other.
  • From a todo-form data should be processed into a pdf-form, which subsequently should be available for further processing such as using as an email attachment.

Now let us consider the third principle possibility of the interaction between todo4teams and a pdf-form:
An incoming e-mail generates a job in todo4teams, this email contains a completed pdf-form as an attachment.
Now the completed pdf-form fields shall be passed directly into a todo4teams-form that is automatically appended to the job in todo4teams plus the fields in this todo-form shall be filled correctly.
A concrete example:
We get the following pdf-form as an attachment to an e-mail, the form name is "formular.pdf".

tutorial14.jpg

The data shall be passed into the todo-form "tutorial PDF", the ID of this form is the 70.

tutorial15.jpg

The properties of the fields of this form we can find in the change dialog within the form management module in todo4teams:

tutorial16.jpg

The logic for the forwarding of the data takes place in the setting dialog of the mailbox  which was registered as the recipient of the email with the specified attachment.
The arrival-action of the mailbox has to be configured using the following Javascript which defines the used forms in todo4teams with their field names and the field names within the pdf:

// Iterate over all attachments
for(ai=0;ai<helper.attachments.length;ai++)
{
   var attachment = helper.attachments[ai];
   // found attachment that is the right pdf
   if(attachment.attachmentName.equals("formular.pdf"))
    {
       // extract pdf fields from pdf form
       var pdfFields=helper.getPdfFormFields(attachment);
      
       // attach todo4teams form
       var md = helper.addMetaData(70);
      
     // iterate over all pdf fields and insert into todo4teams form
          for(i=0;i<pdfFields.length;i++)
        {
          // println (pdfFields[i].name + ">>" +pdfFields[i].value + ">>" +pdfFields[i].ftype);
           var value = pdfFields[i].value;
           var name = pdfFields[i].name;
           var ftype = pdfFields[i].ftype;
           if ((name == "Checkbox1" || name == "Checkbox2") && value == "Yes")
            {
               value = true;
            }
         
         // println (name + ">>" + value);
               helper.addValueForField(md, name, value);
        }
       task.updateMetaContent();
   
    }
}

Brief explanation of the seperate script components:
 The following section specifies the name of the pdf and the ID of the todo-form, which is this case has the ID = 70.

var attachment = helper.attachments[ai];
   // found attachment that is the right pdf
   if(attachment.attachmentName.equals("formular.pdf"))
    {
       // extract pdf fields from pdf form
       var pdfFields=helper.getPdfFormFields(attachment);
      
       // attach todo4teams form
       var md = helper.addMetaData(70);

However, a precondition for the correct transfer of the data is that the field names are identical in both the pdf form as well as in the todo form.
 If this is not the case, or the name of the pdf form can vary from e-mail to e-mail some special adjustments in the script must be made.
 Please contact us for these adjustments under support@bergener-bluma.de.

 In the following part of the script part the actual transfer of the data takes place:

// iterate over all pdf fields and insert into todo4teams form
          for(i=0;i<pdfFields.length;i++)
        {
          // println (pdfFields[i].name + ">>" +pdfFields[i].value + ">>" +pdfFields[i].ftype);
           var value = pdfFields[i].value;
           var name = pdfFields[i].name;
           var ftype = pdfFields[i].ftype;
           if ((name == "Checkbox1" || name == "Checkbox2") && value == "Yes")
            {
               value = true;
            }
         
         // println (name + ">>" + value);
               helper.addValueForField(md, name, value);
        }
       task.updateMetaContent();

For the contents of text fields the passing of data should be no trouble, but some other field types like for example the contents of checkboxes or radio buttons can be quite a challenge. These are not trivial and require a thorough analysis of the pdf.
 The values passed for these types of fields are not standardized and depend on the program with which the pdf form was created.
 In our example there are two checkboxes (Checkbox1 and Checkbox2) which reflect the content of "new customer" and "customer already exists".

 The todo4teams-forms expect as the value of a checkbox either "true" or "false", but only "Yes" and  "Off" are handed over from the pdf-form of our example; these values have to be translated into the appropriate valid values for the todo-form. This is made by the following script component:

var value = pdfFields[i].value;
           var name = pdfFields[i].name;
           var ftype = pdfFields[i].ftype;
           if ((name == "Checkbox1" || name == "Checkbox2") && value == "Yes")
            {
               value = true;
            }
         
         // println (name + ">>" + value);
               helper.addValueForField(md, name, value);

The value "true" is generated from the value "Yes" for check boxes 1 and 2, otherwise the field content remains the same which then automatically results in an unset checkbox with the value "false" for the todo-form.

 In summary, especially the interaction of non-text fields of a pdf-form and the corresponding todo-form is non-trivial and requires a thorough analysis of the field properties. In most cases there have to be made some adjustments and adpations, please contact us support@bergener-bluma.de

     

Child Pages