Journey Manager (JM)
The transaction engine for the platform. |
Form Builder Platform Developer | All versions
This feature is related to all versions.
More than once will you be needing to access an external resource (eg web service, file share or perhaps an external mail server) to do something on submission. Typically you would create a Groovy delivery service and do whatever needs to be done in there. Sometimes this approach is a little problematic if your submission requires a delivery method other than Groovy, like Web Service, REST or Email. It's also possible that you already have an existing delivery channel that is used for other forms, but for this one form you need to do something extra before delivery.
The simple solution is to add the logic to the Submission Completed processor, your external resource will be accessed first and then the normal delivery process will kick. But what if the external resource is temporarily not available, the submission completed process will fail and unfortunately cannot be retried.
Let's leek at how the external resources is accessed from a Groovy delivery process, and how the process will change the delivery for that submission to the final (non-Groovy) delivery process.
For this we assume that we already have a non-Groovy delivery channel configured, called "Test Email", using the standard configuration.
Now, create a new Groovy delivery process, and in this you will be able to do whatever it is that needs be done using something external.
import com.avoka.fc.core.service.DeliveryResult
import com.avoka.fc.core.service.DeliveryResult.Status
import com.avoka.fc.core.dao.DaoFactory
import com.avoka.fc.core.dao.DeliveryDetailsDao
import com.avoka.fc.core.entity.DeliveryDetails
import com.avoka.fc.core.dao.ClientDao
import com.avoka.fc.core.entity.Form
// here starts the work
// step one, do your external resource stuff like call an external database
if (deliveryCheckpoint.doCheckpoint("Access External Resource", "Write db entry")) {
try {
// do the actual method call that does the thing
storeToDb(.....)
deliveryCheckpoint.completedCheckpoint("Access External Resource")
} catch (Throwable e) {
deliveryCheckpoint.errorCheckpoint("Access External Resource", e)
}
}
// now make the submission available for Email delivery service
if (deliveryCheckpoint.doCheckpoint("Email Delivery", "Make submission available for email delivery")) {
try {
// First get a new deliveryDetails object for the client (organisation) and the name of the delivery service you'd like to use
Form form = submission.getForm()
DeliveryDetailsDao deliveryDetailsDao = DaoFactory.getDeliveryDetailsDao()
DeliveryDetails deliveryDetails = deliveryDetailsDao.getDeliveryDetailForClientAndName(
form.getClient(), "Test email")
// Set the delivery details on the submission
submission.setDeliveryDetails(deliveryDetails)
deliveryCheckpoint.completedCheckpoint("Email Delivery")
// and return a ready status so that the submission will be ready for delivery via the newly set delivery process
return new DeliveryResult(Status.READY)
} catch (Throwable e) {
deliveryCheckpoint.errorCheckpoint("Email Delivery", e)
}
}
Then, create a new Delivery Channel for your form's organisation, this channel needs to be of the type "Delivery Process" and make sure you configure it to use your newly created delivery Groovy process.
The last step is to change the delivery channel on your form to use the new Groovy one and not the old Test email service.
Don't try to change the submission's Delivery details object.
If you try to manipulate the submission's delivery details be prepared for some funky result. Most likely the configuration of the delivery channel itself will be set in an inconsistent state. So don't do this.
If you want to re-trigger delivery, the submission will now go through the submission process twice, so be patient. Re-triggering the submission form Manager will now only execute the newly email delivery process, not the original Groovy service.
Next, learn how to view Transact functions.