CodeCharge Studio
// Write your own code here.
with the code below:
String uid = DBTools.toSql(Utils.getUserId(e.getPage()), JDBCConnection.INTEGER, "IntranetDB");
String from = (String)DBTools.dLookUp("email", "employees", "emp_id=" + uid, "IntranetDB");
String to = (String)DBTools.dLookUp("email", "employees", "emp_id=" +
DBTools.toSql(e.getRecord().getControl("user_id_assign_to").getFormattedValue(), JDBCConnection.INTEGER, "IntranetDB"), "IntranetDB");
String host = "mysmtphost.com";
String subject = "New task for you";
String body = "The following task was submitted:<br><br>" +
"Task ID:" + DBTools.dLookUp("max(task_id)", "tasks", "user_id_assign_by=" + uid, "IntranetDB") +
"<br><br>" + e.getRecord().getControl("task_desc").getFormattedValue();
SimpleMailer.sendEmail(from, to, subject, body, true, host);
As you may have realized by now, the above code sends emails to users to whom the new tasks are assigned. The following is an explanation of the code.
String uid = DBTools.toSql(Utils.getUserId(e.getPage()), JDBCConnection.INTEGER, "IntranetDB");
Sets uid variable to the value of the user id of the current user. The static Utils.getUserId function is used to retrieve the current user id.
String from = (String)DBTools.dLookUp("emp_name", "employees", "emp_id=" + uid, "IntranetDB");
Sets from variable to the value of the emp_name field for the current user. The static DBTools.dLookUp function is used to retrieve a database value.
String to = (String)DBTools.dLookUp("email", "employees", "emp_id=" +
DBTools.toSql(e.getRecord().getControl("user_id_assign_to").getFormattedValue(), JDBCConnection.INTEGER, "IntranetDB"), "IntranetDB");
Sets to variable to the email of the person that is assigned to the task. The dLookUp function is used here to retrieve the appropriate email address.
String host = "mysmtphost.com";
The SMTP server that will process the e-mail.
String subject = "New task for you";
The subject of the email to be sent.
String body = "The following task was submitted:<br><br>" +
"Task ID:" + DBTools.dLookUp("max(task_id)", "tasks", "user_id_assign_by=" + uid, "IntranetDB") +
"<br><br>" + e.getRecord().getControl("task_desc").getFormattedValue();
The variable body contains the body of the email which will be sent. The dLookUp function is used to retrieve the largest task id submitted by the current user (assuming that task ids are created incrementally).
SimpleMailer.sendEmail(from, to, subject, body, true, host);
Sends the email using the variables created in the above code. The fifth argument specifies that the mail will be sent in HTML format (as opposed to plain text).
Next: Use the After Update Event to Send Emails