Forum Discussion
This method seems to be a server method so it wont work on field events (field events are JavaScript method). I tried using your method in onAfterUnlock and it works fine for me. Let me know if you are getting any specific error.
Thank You
Gopikrishnan R
Hi Gopkrishnan,
Thank you for your kindly reply.
I did not get any error message, but did not get any email with onAfterUnlock by some reason. Did you make any modification from my code above?
BR,
Jimmi
- Gopikrishnan6 years agoAccelerator II
Below method should work. My changes are highlighted below
Innovator inn = this.getInnovator();
string str_body = "";// Get assignee
Item thisItem = inn.newItem(this.getType(), "get");
thisItem.setAttribute("select", "dlv_assignedto");
thisItem.setID(this.getID());
thisItem = thisItem.apply();
string assignee = thisItem.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 = thisItem.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;
Thank You
Gopikrishnan R
- yanjim6 years agoIdeator III
Thank you for your help! Gopikrishnan
The finally code:
//return inn.newError(string.Format(str_reqby)); //Debugg code
Innovator inn = this.getInnovator();
string str_body = "";// Get assignee
Item thisItem = inn.newItem(this.getType(), "get");
thisItem.setAttribute("select", "dlv_assignedto");
thisItem.setID(this.getID());
thisItem = thisItem.apply();
string assignee = thisItem.getProperty("dlv_assignedto","");
//return inn.newError(string.Format(assignee));//Get Url
Item thisItem2 = inn.newItem(this.getType(), "get");
thisItem2.setAttribute("select", "item_number");
thisItem2.setID(this.getID());
thisItem2 = thisItem2.apply();
string str_actionID = thisItem2.getProperty("item_number","");
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("1241FA3032B3483786BC8DDD0DDF7394"); //DLV_ActionReq_Assignment
email = email.apply();email.setProperty("subject", string.Format("The following Action Request {0} has been assigned to you",str_actionID));
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",str_actionID, link);email.setProperty("body_html", str_body);
// Get Identity for assignee
if ( assignee != "" ) {
Item userItem = this.newItem("User","get");
userItem.setID(assignee);
userItem.setAttribute("select","first_name,last_name");
userItem = userItem.apply();
string username = (userItem.getProperty("first_name") + " " + userItem.getProperty("last_name"));
//return inn.newError(string.Format(username));
Item iden = this.newItem("Identity", "get");
iden.setProperty("name", username);
iden = iden.apply();
if ( iden.getItemCount() == 1) { Boolean result = this.email(email, iden); }
}return this;
- Gopikrishnan6 years agoAccelerator II
Hi Jimmi
I have few suggestions for you.
1. Based on your method, it seems you are doing apply action for 5 times but it can be reduced to 3 server calls. lesser the server call, more the application performance.
2. It is good practice to use the user ID to get the identity than using the user's first name and last name. If first name and last name is modified this method won't work.
3. Since on after unlock event is triggered on every unlock, the mail will trigger two times (assuming DLV is versionable) when you edit an existing item.
Example : I have one DLV item with generation 1. If I edit then it will change to generation 2. So, when I click Unlock, this will unlock generation 1 and generation 2. So method will trigger two time (one for old dlv assigned to another for new dlv assigned to).
This wont be a problem if DLV is not versionable and always have one generation
Based on above suggestions, Modified code is below
Innovator inn = this.getInnovator();
string str_body = "";// Get existing assignee
string existingassignee = this.getProperty("dlv_assignedto","");// Get assignee
Item thisItem = inn.newItem(this.getType(), "get");
thisItem.setAttribute("select", "dlv_assignedto,item_number");
thisItem.setID(this.getID());
thisItem = thisItem.apply();
string assignee = thisItem.getProperty("dlv_assignedto","");if(existingassignee == assignee)
{
return this;
}//Get Url
string str_actionID = thisItem.getProperty("item_number","");
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("35DF32E58F02491B99B0450DA70AF85E"); //DLV_ActionReq_Assignment
email = email.apply();email.setProperty("subject", string.Format("The following Action Request {0} has been assigned to you",str_actionID));
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",str_actionID, link);email.setProperty("body_html", str_body);
// Get Identity for assignee
if ( assignee != "" )
{
Item userItem = inn.newItem("User", "get");
userItem.setAttribute("select", "id");
Item aliasItem = inn.newItem("Alias", "get");
aliasItem.setAttribute("select", "related_id");
Item identity = inn.newItem("Identity", "get");
aliasItem.setPropertyItem("related_id", identity);
userItem.addRelationship(aliasItem);
userItem.setID(assignee);
userItem = userItem.apply();
if (userItem.isError())
{
return userItem;
}
aliasItem = userItem.getRelationships("Alias");
Item iden = aliasItem.getItemByIndex(0).getRelatedItem();
if (iden.getItemCount() == 1)
{
Boolean result = this.email(email, iden);
}
}
return this;Thank You
Gopikrishnan R