Fetch and Email Data
Table of Contents
Overview
Assume you want visitors to subscribe to a newsletter through a subscription Form and send mail to the e-mail ids of subscribed users. The Application should also allow subscribers to unsubscribe from the newsletter. The sample application Subscribe to Newsletter illustrates this scenario.The Application has three forms:
Subscription Form
The Form to subscribe to the newsletter. It has the Name and email-id fields to enable visitors to subscribe to the newsletter by specifying their e-mail ids. There is also one hidden field “isUnsubscribed” to check the status of each subscription. This field is hidden when the form is loaded. The on add ->on load script given below, hides the isUnsubscribed field, when form is loaded.
on add
{
on load
{
hide isUnsubscribed;
}
}
Send Mail Form
This Form is used by the owner to send mails to the subscribers mailing list. It has the Send decision check-box field which when set to “true” will send e-mails to the subscriber mailing list. This is achieved by adding on user input script to the Send field as given below.
Send
(
type = checkbox
defaultvalue = false
on user input
{
if (input.Send)
{
for each r in Subscription_Form [isUnsubscribed == false]
{
sendmail
(
To : r.EmailId
From : zoho.adminuserid
Subject : "Regarding subscription to our newsletter"
Message : "Your subscription is approved"
)
}
}
}
Code Explanation
- if(input.Send) – The if statements will be executed if the Send decision check-box is set to true.
- for each r in Subscription_Form [isUnsubscribed == false] – Here, isUnsubscribed is a Decision Check field and r is a variable that stores the records whose isUnsubscribed status is false.
- sendmail – Send mail to the e-mail id specified in the row variable r.
Unsubscribe Form
The Form is used to unsubscribe from the newsletter. This Form contains the e-mailId field, using which the user unsubscribes from the newsletter. When a user submits his e-mailid, the On Add ->On Success script added to this form, updates the decision checkbox field isUnsubscribed in the Subscription form to true, as shown in the code given below:
on add
{
on success
{
temp = Subscription_Form [EmailId == input.EmailId];
temp.isUnsubscribed = true;
}
}
Code Explanation
temp = Subscription_Form [EmailId == input.EmailId];
The above code will fetch records from the Subscription Form whose EmailId is equal to the EmailId specified in this form, and store it in a collection variable named temp.
temp.isUnsubscribed = true;
The above code sets the isUnsubscribed field in the fetched record to true.
Related Links
Install the application
To install the application,
- Navigate to this link, and download Subscribe_to_Newsletter.ds
- Install the application to your account.Click here to learn how to install using the script file (.ds file).