1
0
-1

Hi, 

Does anyone have any ideas how to customise the attachment file name of certain format/pattern?

For example, the customer attached a file named 'Test.doc', we would like the delivery email attaches the file name as 'Composer.doc' instead of  'Test.doc'.

Thanks

Sindy

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      For the benefit of anyone else interested in this ticket, here is an example script for a possible solution to this issue:


      import com.avoka.fc.core.dao.SubmissionDao
      import com.avoka.core.groovy.GroovyLogger as logger
      import com.avoka.fc.core.dao.AttachmentDao
      import com.avoka.fc.forms.api.Attachment
      import com.avoka.fc.core.dao.DaoFactory
      import com.avoka.fc.core.entity.Submission
      import org.apache.click.servlet.MockRequest
      import com.avoka.fc.core.entity.SchemaSeed
      //get submission from tracking number as submissionDao
      SubmissionDao subDao = new SubmissionDao();
      def sub = subDao.getSubmissionByTrackingNumber('ABCDEF');
      //get attachments
      AttachmentDao attachDao = new AttachmentDao();
      def attachments = attachDao.getSubmissionFileAttachments(sub);
      attachments.each { attachment ->
      def fullname = attachment.getFileUpload().getFileName()
      def extention = fullname[fullname.lastIndexOf('.')..fullname.length()-1]
      def filename = fullname[0..fullname.lastIndexOf('.')-1]
      //file name information
      def username = sub.formDataMap.firstName
      def date = new Date().format('ddMyyyy');
      def newName = filename + " by " + username + " " + date + extention
      //get attachment file
      def fileUpload = attachment.getFileUpload()
      //change file name
      fileUpload.setFileName(newName)
      //change file to new one
      attachment.setFileUpload(fileUpload)
      println attachment.getFileUpload().getFileName()
      sub.getObjectContext().commitChanges();
      }


      Regards,

      Joel



        CommentAdd your comment...