Send email to task assignee by field event

Hi,

We have a customized task request application in Aras and I want to build a method to send assignee an email when the task has been assigned to the person.

I want to add the method to a field event, onChange. So, when the assignee changes value, an email will be sent. See attached screenshots.

And my code:

Innovator inn = this.getInnovator();
string str_body = "";

// Get assignee
string assignee = this.getProperty("dlv_assignedto","");

//Get Url
string str_actionID = this.getProperty("id","");
string str_actionReq = "DLV_ActionReq";
string link = string.Format(@"<html><p><a href=""{2}/Default.aspx?StartItem={0}:{1}"">Click here to open the ticket</a></p></html>",str_actionReq, str_actionID, CCO.Request.Url.ToString().Substring(0,CCO.Request.Url.ToString().IndexOf("/Server/")));

// Get Mail
Item email = inn.newItem("Email Message", "get");
email.setID("11A395B11B3A4337AE24F539266E815D");
email = email.apply();

email.setProperty("subject", string.Format("The following Action Request {0} has been assigned to you",this.getProperty("item_number","")));
str_body = string.Format(@"<html><B>The following Action Request {0} has been assigned to you. <br>{1} <br>Best regards,<br>Engineering Capability Office",this.getProperty("item_number",""), link);

email.setProperty("body_html", str_body);

// Get Identity for assignee
if ( assignee != "" ) {
string str_reqby = this.getPropertyAttribute("dlv_assignedto", "keyed_name");
Item iden = this.newItem("Identity", "get");
iden.setProperty("name", str_reqby);
iden = iden.apply();
if ( iden.getItemCount() == 1) { Boolean result = this.email(email, iden); }
}

return this;

---------------------------------------------------

Any idea why it does not work?

Have tried with server events, onAfterUpdate and it works. But not working with onAfterUnlock, it will solve my problem as well.

Best Regards,

Jimmi