Requirement
Users should be able to choose if they want to subscribe to or unsubscribe from a periodic newsletter email.
Use Case
A fintech company sends monthly newsletters to its customers. Customers should have the option to subscribe or unsubscribe to the newsletter at any point of time.
Steps to follow
Form | Form Link Name | Field Type | Field Name | Field Link Name |
Opt In | Opt_In | Add Notes | I want to receive updates | plain |
Name | Name | Name |
Email | Email | Email |
Opt Out | Opt_Out | Add Notes | I do not want any further updates | plain |
Email | Email | Email |
Name | Name | Name |
The Opt In form is used by customers to sign up for the monthly newsletter. The Opt Out form is used by customers to unsubscribe from the monthly newsletter.
2.
Create workflow with the following details to restrict duplicate email IDs.
We are using the Form Event as Validations on form submission so that the entered email address can be checked before the data is added to the database.
3. Click Add New Action and add the following snippet in the Deluge editor.
- // check if any duplicate records exist and alert the user if yes
- duplicate_records_count = Opt_In[Email == input.Email].count();
- if(duplicate_records_count != 0)
- {
- alert "This email is already registered for updates";
- cancel submit;
- }
Now let's add workflows to the Opt Out form to achieve the following:
- Disable Name field
- Fetch data and populate Name field based on the entered email address
- Display an alert when then entered email address does not exist in database
- Remove the email address from Opt In form after form submission
4. Create workflow with the following details to disable the name field.
5. Click Add New Action and save the following snippet in the Deluge editor.
6. Create a new workflow with the following details.
The Form Event is selected as User input of a field so that the corresponding Name value can be fetched when an email address is entered.
7. Click Add New Action and save the following snippet in the Deluge editor.
- // fetch the record containing the email address
- fet = Opt_In[Email == input.Email];
- // if the record exists, assign the corresponding name to the Name field, and display an alert to the user that the email will be removed from the list
- if (fet.Email != null)
- {
- input.Name = fet.Name;
- alert ("This email is registered with the name " + input.Name) + " and will be removed from the updates list";
- }
8. Create another workflow as below to display an error if the email is not found/subscribed
We are using the Form Event as Validations on form submission so that the entered email address can be checked before the data is added to the database.
9. Click Add New Action and save the following snippet in the Deluge editor.
- // fetch the record containing the email address
- fet = Opt_In[Email == input.Email];
- // if the email address is not found, display an alert and restrict the form submission
- if(fet.Email == null)
- {
- alert "This email is not registered for updates";
- cancel submit;
- }
10. Lastly, create a workflow as displayed, to remove the email address from the subscription list on successful form submission.
11. Click Add New Action > Deluge Script, and save the following script in the Deluge editor.
- // delete the record in Opt In form which contains the specfied email address
- delete from Opt_In[Email == input.Email];
See how it works
Points to note
- Permissions can be used to hide the reports from users.
- The email list in the Opt In form can be used to send periodic emails or newsletters using schedules.
- Workflows
- Form events in workflows