1
0
-1

Hi Team,

How do can setup regular, reminder email notifications to the form submitted user about the submission status? 

Eg: Email reminder that save draft is due to expire.

      Email reminder to user about their form delivery status change

 

    CommentAdd your comment...

    3 answers

    1.  
      1
      0
      -1

      Hi Jim,

      There is service which is programmed to do a similar job but fails due to null point exception.Please look below the code that throws this error. Can you please the functionality of below snippet 

      "java.lang.IllegalArgumentException: Null portal parameter"



      def model = [
      resumeUrl: PortalUtils.getSaveChallengeUrl(portal, submission),
      submission: submission,
      format: new EmailFormat()
      ];

       

       

        CommentAdd your comment...
      1.  
        1
        0
        -1

        Here is a simpler example:-

         

        /* A Groovy script scheduled service which is invoked by a ScheduledServiceJob.

        Script parameters include: 
        serviceDefinition : com.avoka.fc.core.entity.ServiceDefinition
        serviceParameters : Map<String, String>)

        Script return:
        string message to be logged to the server log as an INFO message
        */

        import groovy.json.JsonSlurper;
        import groovy.time.TimeCategory;
        import groovy.time.TimeDuration;

        import javax.mail.internet.InternetAddress;
        import javax.mail.internet.AddressException;

        import com.avoka.fc.core.dao.DaoFactory;
        import com.avoka.fc.core.service.ServiceFactory;
        import com.avoka.fc.core.util.PortalUtils;
        import com.avoka.fc.core.service.EmailService.EmailFormat;

        import org.apache.cayenne.BaseContext;


        def log = [];

        def getTimeoutForType = { reminderType -> 
        new JsonSlurper().parseText(
        serviceParameters["timeoutJson-${reminderType.id}"]
        );
        }

        def getSavedSubmissionMap = {
        def subMap = [];

        def clientDao = DaoFactory.clientDao;
        def submissionDao = DaoFactory.submissionDao;
        def code = "client-onboarding";
        def aClient = clientDao.getClientByCode("Client");

        submissionDao.getSavedSubmissionList(
        null, aClient.getId().toString(), null, null, null, null
        ).findAll {
        // Only onboarding forms

        if(code.contains(it.formCode))
        {
        def formDataMap = it.getFormDataMap();
        if( formDataMap.route == "Customer Form")
        {
        def now = new Date();
        def sub = it.submissionHistory.last().datetimeCreated;
        if((TimeCategory.minus(date, sub)) <= 14)
        {

        submap.add(it);
        }
        }
        }
        };

        return subMap;
        }

        def getLastSaveDate = { submission ->
        submission.submissionHistory.last().datetimeCreated;
        }

        def lastSaveMoreThan = { submission, duration ->
        def now = new Date();
        def saved = getLastSaveDate(submission);

        return TimeCategory.minus(now, saved) >= duration; 
        }

        def isValidEmail = { email -> 
        if (email) {
        def parsed = new InternetAddress(email);

        try {
        parsed.validate();

        return true;
        } catch (AddressException e) {
        return false; 
        }
        }

        return false;
        }

        def sendReminderEmail = { submission, size ->
        def emailService = ServiceFactory.emailService;
        def portal = submission.portal;
        def recipient = submission.contactEmailAddress;

        // If we don't have a contact email, we can't continue
        if (!isValidEmail(recipient)) {
        log.add("WARN: Invalid email address \"${recipient}\" for submission ${submission.submitKey}");

        return;
        }

        def subject = "Incomplete Application";

        def body = '''<p>REMINDER - $submission.formName FORM SAVED </p>
        <p>You recently commenced an application with us.
        #if ($submission.submissionExpiryDate) 
        Please be aware that your saved application will expire on $format.date($submission.submissionExpiryDate, 'd MMMM yyyy').
        #end
        </p>
        <p>If you are having difficulties completing the form please call our Client Services team on 1300 1999999 between Monday - Friday: 8:00am – 6:00pm and Saturday: 9.00am - 12.00pm (All times AEST).</p>
        <p>
        $submission.submitKey
        <a href="${resumeUrl}">Please click here to return to the form and finalise your application</a>
        </p>
        <p><em>Please note: you may be required to answer a security question to access the form.</em></p>
        ''';

        def model = [
        resumeUrl: PortalUtils.getSaveChallengeUrl(portal, submission),
        submission: submission,
        format: new EmailFormat()
        ];

        emailService.sendTemplatedMessageForPortal(
        recipient, subject, body, model, portal
        );

        //submission.setSubmissionPropertyValue("ReminderSent", "true");

        //BaseContext.getThreadObjectContext().commitChanges();

        /*log.add(
        "INFO: Sent reminder email for ${type.desc} submission ${submission.submitKey} to ${recipient}"
        );*/
        }

        def savedSubmissions = getSavedSubmissionMap();

        for( i = 0; i < savedSubmissions.size(); i++)
        {
        sendReminderEmail(savedSubmissions.get(i), savedSubmissions.size());
        }

        return log.join("\n");

          CommentAdd your comment...
        1.  
          1
          0
          -1

          Hi Maseer,

           You can do this with a groovy service and a scheduled job:-

           

           

          Reminder Email code (this one has several filters for different reminder so is quite complicated):-

          /* A Groovy script scheduled service which is invoked by a ScheduledServiceJob.

          Script parameters include:
          serviceDefinition : com.avoka.fc.core.entity.ServiceDefinition
          serviceParameters : Map<String, String>)

          Script return:
          string message to be logged to the server log as an INFO message
          */

          import groovy.json.JsonSlurper;
          import groovy.time.TimeCategory;
          import groovy.time.TimeDuration;

          import javax.mail.internet.InternetAddress;
          import javax.mail.internet.AddressException;

          import com.avoka.fc.core.dao.DaoFactory;
          import com.avoka.fc.core.service.ServiceFactory;
          import com.avoka.fc.core.util.PortalUtils;
          import com.avoka.fc.core.service.EmailService.EmailFormat;

          import org.apache.cayenne.BaseContext;

          enum REMINDER_TYPES {
          MANUAL("manualSaved", "manually saved"),
          BGSAVED("bgSaved", "background saved"),
          ASSIGNED("assigned", "assigned")

          final String id;
          final String desc;

          private REMINDER_TYPES(id, desc) {
          this.id = id;
          this.desc = desc;
          }
          }

          def log = [];

          def getTimeoutForType = { reminderType ->
          new JsonSlurper().parseText(
          serviceParameters["timeoutJson-${reminderType.id}"]
          );
          }

          def getSavedSubmissionMap = {
          def subMap = [
          manualSaved: [],
          bgSaved: [],
          assigned: []
          ];

          def clientDao = DaoFactory.clientDao;
          def submissionDao = DaoFactory.submissionDao;

          def aClient = clientDao.getClientByCode("CLIENTNAME");

          submissionDao.getSavedSubmissionList(
          null, aClient.getId().toString(), null, null, null, null
          ).findAll {
          // Only loan forms
          it.formCode == "loan-app";
          }.findAll {
          // Only include forms for which the reminder hasn't already been sent
          it.getSubmissionPropertyValue("ReminderSent") == null;
          }.findAll {
          // Filter out modify submissions
          it.getSubmissionPropertyValue("OrigJobKey") == null;
          }.findAll {
          // Remove all manually saved submissions & add to list
          if (it.formDataMap.isManualSave == "true") {
          subMap.manualSaved.add(it);

          return false;
          }

          return true;
          }.findAll {
          // Remove all background-saved submissions, adding to bgSaved list
          def isBgSaved = it.isBackgroundSavedFlag()

          if (isBgSaved) {
          subMap.bgSaved.add(it);
          }

          return !isBgSaved;
          }.findAll {
          // Remove all assigned submissions, adding to assigned list
          def isAssigned = (
          it.jobAction != null &&
          it.jobAction.name == "Assign Trustee Forms" &&
          it.revisionNumber == 1
          );

          if (isAssigned) {
          subMap.assigned.add(it);
          }

          return !isAssigned;
          };

          return subMap;
          }

          def getLastSaveDate = { submission ->
          submission.submissionHistory.last().datetimeCreated;
          }

          def lastSaveMoreThan = { submission, duration ->
          def now = new Date();
          def saved = getLastSaveDate(submission);

          return TimeCategory.minus(now, saved) >= duration;
          }

          def isValidEmail = { email ->
          if (email) {
          def parsed = new InternetAddress(email);

          try {
          parsed.validate();

          return true;
          } catch (AddressException e) {
          return false;
          }
          }

          return false;
          }

          def sendReminderEmail = { submission, type ->
          def emailService = ServiceFactory.emailService;
          def portal = submission.portal;
          def recipient = submission.contactEmailAddress;

          // If we don't have a contact email, we can't continue
          if (!isValidEmail(recipient)) {
          log.add("WARN: Invalid email address \"${recipient}\" for submission ${submission.submitKey}");

          return;
          }

          def subject = "Incomplete LoanApplication";

          def body = '''REMINDER - FORM SAVED
          <p>You recently commenced a loan application.
          #if ($submission.submissionExpiryDate)
          Please be aware that your saved application will expire on $format.date($submission.submissionExpiryDate, 'd MMMM yyyy').
          #end
          </p>
          <p>If you are having difficulties completing the form please call our Client Services team on 1800 999 999 between 8:30am and 5:30pm Sydney time, Monday to Friday.</p>
          <p>
          <a href="${resumeUrl}">Please click here to return to the form and finalise your application</a>
          </p>
          <p><em>Please note: you may be required to answer a security question to access the form.</em></p>
          ''';

          def model = [
          reminderType: type.desc,
          resumeUrl: PortalUtils.getSaveChallengeUrl(portal, submission),
          submission: submission,
          format: new EmailFormat()
          ];

          emailService.sendTemplatedMessageForPortal(
          recipient, subject, body, model, portal
          );

          submission.setSubmissionPropertyValue("ReminderSent", "true");

          BaseContext.getThreadObjectContext().commitChanges();

          log.add(
          "INFO: Sent reminder email for ${type.desc} submission ${submission.submitKey} to ${recipient}"
          );
          }

          def savedSubmissions = getSavedSubmissionMap();

          REMINDER_TYPES.eachWithIndex { reminderType, index ->
          log.add(index, "INFO: Number of ${reminderType} ${savedSubmissions[reminderType.id].size()}");

          savedSubmissions[reminderType.id]
          .findAll(lastSaveMoreThan.rcurry(
          new TimeDuration(*getTimeoutForType(reminderType)))
          )
          .each(sendReminderEmail.rcurry(reminderType));

          }

          return log.join("\n");

           

           

            CommentAdd your comment...