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

Script Library

  Send an email based on a database event
 
  chubbard posted this script:
  Frequently, you will want to send an email when there is some activity on a table -- a user inserts a record, someone updates field data in a record, etc.

To use:
- go to the table in question
- click the scripts tab
- use the drop down to indicate when you want the script to run.
- this will append the appropriate function to your script
- within the braces of that function, place this code

var emailObj = new email();
emailObj.from = "webowner@mail.com";
emailObj.replyTo = "webowner@mail.com";
emailObj.to = user.email;
             emailObj.cc = "otherfriend@westside.com";
             emailObj.bcc = "secretfriend@westside.com";
             emailObj.contentType = "text/html";
   emailObj.subject = "Your entry: " + record.myField;

             emailObj.body = "Dear " + record.ownedBy + ", you added a new record on: " + record.created  ;

emailObj.send();



Note that anywhere on this email object, you can any combination of strings or fields from the record being submitted.  

You can format the body of this email by inserting line breaks within strings in the body of the email.
 
  on 2001-04-03 06:12:13, chubbard responded:
  It is also possible to do this using the Westside specific JavaScript extension <ws:email>.  The above example converts to:

var emailObj =

<ws:email>
To:<%=user.email%>
Cc:otherfriend@westside.com
Bcc:secretfriend@westside.com
From:webowner@mail.com
ReplyTo:webowner@mail.com
ContentType:text/html
Subject:Your entry:<%=record.myField%>
Body:
<font face="verdana,arial,sans-serif" size="2">
Dear <%=record.ownedBy%>,<br><br>

You added a new record on: <%=record.created%><br><br>

Sincerely,<br><br>

The web owner.<br><br>

<a href="http://theweb.westside.com/default.view">
  <img src="http://theweb.westside.com/images/logo.gif" width="50" height="50" border="0">
</a>
</font>
</ws:email>;

emailObj.send();

Note that it is a lot easier to deal with complex formatting using this method.

Westside script extensions are covered more fully in the help at:

http://help.westside.com/default.view?Topic=westsidescript/wsextensions
 
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