Issue
How can I dynamically set an email template for a WorkflowGen notification?
Background
In a WorkflowGen action notification tab, you can select an email template for each additional notification. You can create as many notifications as required with combination of different templates and conditions. However, you may not want to create the same set of notifications for multiple actions because it will be time consuming.
Solution
You can predefine the final email template by manipulating one eFormASPX action to decide which email template you would like to use and set the template file before the notification is triggered.
First you will need to prepare the different email template files as file type process data. This is no different than how you would normally create email templates. Next, create an empty file type process data that will hold the selected template file. Make sure this empty file type process data is not set as read only.
Assuming there are 3 different template files you would like to choose from based on certain conditions, on your web form, create 4 hidden Label or TextBox controls for the template files. Usually a file type data requires a File Upload control. But in this case, you dont need the user to interact with the template files.
Also, for simplicity, let assume the IDs of these 4 controls are as follows: TEMPLATE1, TEMPLATE2, TEMPLATE3, and SELECTED_TEMPLATE and the names of the 4 process data are: EMAIL_TEMPLATE1, EMAIL_TEMPLATE2, EMAIL_TEMPLATE3, APPROVER_TEMPLATE.
In the action prior to the action that will trigger the notification, pass the template process data as IN parameter values and pass the selected one as OUT parameter:
TEMPLATE1 IN EMAIL_TEMPLATE1
TEMPLATE2 IN EMAIL_TEMPLATE2
TEMPLATE3 IN EMAIL_TEMPLATE3
SELECTED_TEMPLATE OUT APPROVER_TEMPLATE
The WorkflowGen library will allocate the 3 template files to the hidden controls when the page is loaded. In your web form code-behind, you must add your logic to specify which template you would like to choose prior to the submission of the form. You can have conditions such as the following:
C#
if (your condition) {
this.SELECTED_TEMPLATE.Text = this.TEMPLATEx.Text;
}
The above code will copy the file reference from the selected template (TEMPLATEx) to the final template (SELECTED_TEMPLATE) placeholder. Once the form is submitted, the file reference will be passed as an OUT parameter to the process data APPROVER_TEMPLATE. In your action notifications, you will be able to use the same process data APPROVER_TEMPLATE as your template for the various emails to be sent out.