Search these areas:
Help
Support Forums
Product Info



-Introduction
-DataWeb: What's New
-Creating an Application
-The DataWeb Designer
-Application Management
-Data Tables
-Data Tables
-Views
-Templates
-Components
-Data Analysis
-Members
-Security
-Importing
-Exporting
-FTP
-JavaScript
-Object Model
-Full-Text Search
-Domain and Email Hosting
-HotBlock Modules
-Account Management
-Glossary
-New Responsive UI Module





DataWeb Help
Support Forums
Tutorial
Script Library
Knowledge Base

Home > Support

Support Forum



SENDING E-MAILED COPY OF VIEW
rachel asked:
I would like to have a copy of the information after it is submitted to a view to be sent to our company via e-mail. How would I set this up?  
  psiegel responded:
  Well, for starters, let's set up a scenario that we'll use for sending the emails:

1. Your view collects some user information and stores it in a table called UserInfo.
2. The information you collect are a person's first name, his/her favorite ice cream flavor, and email address.
3. The user's first name is stored in a field called FirstName, the user's email is stored in a field called Email, and the flavor is stored in a field called Flavor,
4. You would like to send an email to the person who submitted their information to let them know that their flavor preference has been stored.

Here's one way to setup sending the user an e-mail when a user inserts new information into the table:

First, we'll write a function that creates the body of the e-mail.
Second, within the function, we'll create an Email object to construct the email and send it to the user.
Finally, we'll call the function within the Data_AfterInsert class script on the UserInfo table so that it runs each time a user inserts information into the UserInfo table.

Here's the function that builds the email based on information passed to it.

function registrationEmail(firstName,flavor,userEmail) {

    var mailTo, mailFrom, mailBody, mailSubject;

    // build the body of the email
    mailBody = "Dear " + firstName + ",<br/><br/>";
    mailBody = mailBody + "Your ice cream preference of <b>" + flavor + "</b> has been stored.<br/><br/>";
    mailBody = mailBody + "Thank you for registering!";
    // set the email recipient
    mailTo = userEmail; // get the user's email address
    // set the sender
    mailFrom = "sender@IceCream.icy";
    // set the subject of the email
    mailSubject = "Your ice cream preferences have been saved!";

    // construct the email
    var e = new Email();
    e.contentType = "text/html";
    e.to = mailTo;
    e.from = mailFrom;
    e.subject = mailSubject;
    e.body = mailBody;
    // send it!
    e.send();
}

Next, place the function in the data class script of the UserInfo table.

Lastly, we'll call the new function from the Data_AfterInsert function also within the data class script of the UserInfo table.

function Data_AfterInsert() {
    registrationEmail(record.firstName,record.flavor,record.email);
}

That's it!


For more information, here are some relevant references:

Email Object: http://support.dataweb.com/Help/default.view?Topic=objectmodel/email/wsemailobject

Calling Functions from Data Class Scripts: http://support.dataweb.com/Help/default.view?Topic=westsidescript/dataclasses/wsdataclasscall
 
  rachel responded:
  If you don't already you are going to think I am real stupid.  Where exactly do we put these functions everyone is talking about? Do you put them in the source section of the view? That does it I'm sure you give up now. I want to send the e-mail to us. So it will be a constant(always to us)Thanks for your patience.  
  psiegel responded:
  We were all new to the platform at one time... :-)

Basically, there are three places you can include script:

1. Within a .view file

    The following article will help you understand how to include script in views.

    HostRAD Substitution Syntax: http://support.dataweb.com/Help/default.view?Topic=views/vaddingscripts/poundDelim

2. On the Scripts tab when viewing a table (.data) in the Builder.

    Here is a different article than I mentioned above regarding Data Classes that might explain this concept a little more.

    Creating Scripts in a Data Class: http://support.dataweb.com/Help/default.view?Topic=westsidescript/dataclasses/wsdataclasscreate

3. Within a .ws file

    These files are basically script-only files that can be imported into and referenced from other files.

    Here's an article that explains that concept a bit more clearly as well.

    Calling Functions: http://support.dataweb.com/Help/default.view?Topic=views/vaddingscripts/callingfunctions
 
  Please Log On
or create your own DataWeb Account.
Affiliate | Partner | Terms of Use | Privacy Policy | Contact Us | Pricing | Bring DataWeb In-House    
DataWeb, 720 North 10th Street, A #145, Renton, Washington 98057 *425-583-5970* Fax 484-770-4706* Email Us