CodeCharge Studio
// Write your own code here.
with the code below:
$DBIntranetDB = clsDBIntranetDB->new();
$from_name = CCDlookUp("emp_name", "employees", "emp_id=" . $DBIntranetDB->ToSQL(CCGetSession("UserID"), $ccsInteger), $DBIntranetDB);
$from_email = CCDlookUp("email", "employees", "emp_id=" . $DBIntranetDB->ToSQL(CCGetSession("UserID"), $ccsInteger), $DBIntranetDB);
$to_email= CCDlookUp("email", "employees", "emp_id=" .
$DBIntranetDB->ToSQL($tasks->{user_id_assign_to}->GetValue(), $ccsInteger), $DBIntranetDB);
$subject = "New task for you";
$message = "The following task was submitted:<br><br>" .
"Task ID: " . CCDlookUp("max(task_id)", "tasks", "user_id_assign_by=" .
$DBIntranetDB->ToSQL(CCGetSession("UserID"), $ccsInteger), $DBIntranetDB) . "<br><br>" .
$tasks->{task_desc}->GetValue();
if(open(SENDMAIL, "| sendmail $from_name"))
{
print SENDMAIL "From: $from_email\nTo: $to_email\nSubject: $subject\n\n$message\n.\n";
close(SENDMAIL);
}
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.
$from_name = CCDlookUp("emp_name", "employees", "emp_id=" . $DBIntranetDB->ToSQL(CCGetSession("UserID"), $ccsInteger), $DBIntranetDB);
Sets from_name to the value of the emp_name field for the current user.
$from_email = CCDlookUp("email", "employees", "emp_id=" . $DBIntranetDB->ToSQL(CCGetSession("UserID"), $ccsInteger), $DBIntranetDB);
Sets from_email to the value of the email field in the employees table where emp_id matches the current user. The CCDlookUp function is used to retrieve a database value, while CCGetSession("UserID") retrieves the id of the currently logged in user.
$to_email= CCDlookUp("email", "employees", "emp_id=" . $DBIntranetDB->ToSQL($tasks->{user_id_assign_to}->GetValue(), $ccsInteger), $DBIntranetDB);
Sets to_email to the email of the person that is assigned to the task. The CCDlookUp function is used here to retrieve the ppropriate email address.
$subject = "New task for you";
The subject of the email to be sent.
$message = "The following task was submitted:<br><br>" . "Task ID: " . CCDlookUp("max(task_id)", "tasks", "user_id_assign_by=" . $DBIntranetDB->ToSQL(CCGetSession("UserID"), $ccsInteger), $DBIntranetDB) . "<br><br>" . $tasks->{task_desc}->GetValue();
The variable message contains the body of the email which will be sent. The CCDlookUp function is used to retrieve the largest task id submitted by the current user (assuming that task ids are created incrementally).
if(open(SENDMAIL, "| sendmail $from_name"))
{
print SENDMAIL "From: $from_email\nTo: $to_email\nSubject: $subject\n\n$message\n.\n";
close(SENDMAIL);
}
Sends the email using the variables created in the above code.
Next: Use the After Update Event to Send Emails