Some forms require multiple attachments when delivered back to an organisation.
Can you configure in TM to Zip these and place in File directory?
  1. Chantal Thomas
    Yes, This can be done in a custom Groovy Delivery service.
  2. Matthew van Bockel
    There are a couple of additional things to keep in mind:

    • Groovy Delivery Service definitions in Transact Integration Agent are slightly different to Transaction Manager.

    For example, a Transaction Manager Groovy Delivery Service will provide:

    attachmentsMap : Map<String, com.avoka.fc.form.service.DataDocument>

    Whereas a Transact Integration Agent Groovy Delivery Service will provide:

    attachmentList : List<com.avoka.fc.forms.api.Attachment>

    • You may need to consider what needs to happen if attachment file names are not unique. Here's one way of appending an index '01', '02' to the name:

    def String prevName = ""
    def int index = 0
    // sort attachments by name
    attachmentList.sort{ a,b -> a.getFileName() <=> b.getFileName() };
    // iterate through the collection (an Integration Agent collection in this example)
    for (Attachment attachment : attachmentList) {
    // optional check to see if this attachment is supplied out-of-band
    if (!attachment.isSubmittedManuallyFlag()) {
    // check attachment name
    def String name = attachment.getFileName()
    // check for previously matched name, irrespective of case-sensitivity or the target directory
    if(prevName.equalsIgnoreCase(name)) {
    // match detected, increment the index, zero-pad and append to the name value
    name = name + (index<10 ? '0'+index : index)
    else {
    // update the prevName value to the attachment name we are processing now
    prevName = name
    // reset the index value as the prevName value has changed
    index = 0
    // optional: may also need to replace reserved characters in the name, e.g. for Windows OS
    name = name.replaceAll("[<>\\\"\\\\/|:\\?\\*]", "")

CommentAdd your comment...

1 answer

    1. Jye Cusch
      Hi Nelly,
      Expanding a little on Chantal's response, a custom 'Delivery Process' written in Groovy would be the best way to achieve what you're after. This can be done in TM > System > Service Definitions by clicking 'New Groovy Service' and selecting 'Delivery Process' as the 'Service Type'. Once your service definition is created you will need to edit the contents of the 'groovyScript' service parameter from the 'Service Parameters' tab.

      Below is an example Groovy script that achieves something similiar to what you're asking, namely it takes the attachments from a form submission, zips them into a single file called 'attachments.zip' and saves them to the file system.
      Note: This script is an example only, thorough testing and review should be done before using this script in any production environment.

      import java.nio.file.Files
      import java.nio.file.Paths
      import java.nio.file.StandardOpenOption
      import java.nio.channels.FileChannel
      import java.util.zip.ZipOutputStream
      import java.util.zip.ZipEntry
      //Ensure attachments exist
      if(attachmentsMap.size() > 0){

      //Configure and create an output directory
      def destPath = 'C:/deliveries/delivery-' + submission.id + '/attachments.zip'

      ByteArrayOutputStream baos = new ByteArrayOutputStream()
      ZipOutputStream zipFile = new ZipOutputStream(baos)

      //Write each attachment to the ZipOutputStream
      attachmentsMap.each{ name, dataDoc ->

      zipFile.putNextEntry(new ZipEntry(dataDoc.getName()))
      zipFile << dataDoc.getBytes()


      //Write the zip out to a file
      Files.write(Paths.get(destPath), baos.toByteArray(), StandardOpenOption.CREATE)

    CommentAdd your comment...