1
0
-1

Hi,

 

We have a form which the customer fills in and goes to an internal email address - the people who have requested the form are asking for it to be sent to a different email address when a certain option (as a drop down) is selected.

Is this possible, and could someone point me to the documentation that would clarify how to do this?

Thanks

Richard

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      Hi Richard,

       

      The easiest way to do this (and have full control of the destination) is to create a Groovy delivery service that does this. 

       

      I've added a code sample below. This script depends on a two service parameters:

      • emailContent: the body of the email. You can use Velocity markup to merge content from your form submission in the text

      • emailSubject: the subject of the email

       

      The email address is (for this example) retrieved from the formDataMap. You will have to ensure that the correct data extract mapping has been configured for your form.

       

      I hope this answers your question.

       

      Jeroen

       

      /* Provides a Groovy script based submission delivery process.
         Script parameters include: 
              submission : com.avoka.fc.core.entity.Submission
              submissionXml : String
              receiptPDF : byte[]
              attachmentsMap : Map<String, com.avoka.fc.form.service.DataDocument>
              deliveryCheckpoint : com.avoka.fc.core.service.submission.DeliveryCheckpointService
              serviceDefinition : com.avoka.fc.core.entity.ServiceDefinition
              serviceParameters : Map<String, String>
              deliveryDetails : com.avoka.fc.core.entity.DeliveryDetails
              formDataMap : Map<String, String>
           
          Script return:
              null or 
              deliveryResult : com.avoka.fc.core.service.DeliveryResult   
      */
      import com.avoka.fc.core.service.EmailService;
      import com.avoka.core.util.StringTemplate
      import com.avoka.fc.form.service.DataDocument
      def checkpointA = "Delivery Checkpoint 'Email'"
      if (!deliveryCheckpoint.isCompleted(checkpointA)) {
        
        deliveryCheckpoint.registerCheckpoint(checkpointA, "Sending Email")
        
        try {
          // Send mail with attachments
      	def emailService = new EmailService();
          // attach/include the receipt into the attachments map
          attachmentsMap.put("Groovy Email Service", new DataDocument(receiptPDF, "application/pdf", "My Receipy.pdf"));
          // The email address used is picked up from the form, make sure
          // the form data extract has been configired to extract the address
      	def emailaddress = formDataMap.get("email")
          if (emailaddress) {
            // Get the email text and merge any other data fields from the form data extract
            def template = new StringTemplate(serviceParameters.emailContent)
            def message  = template.merge(formDataMap)
            
            emailService.sendMessageWithSubmissionAttachments(serviceParameters.emailSubject, message, "", emailaddress, attachmentsMap)
          }
          
        	deliveryCheckpoint.completedCheckpoint(checkpointA, "Email sent")
          
        } catch (Exception e) {
          deliveryCheckpoint.errorCheckpoint(checkpointA, e)
        }    
      }
        CommentAdd your comment...