Forum Discussion

yanjim's avatar
yanjim
Ideator I
6 years ago
Solved

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

  • 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

  • Hi Yanjim

    I would propose some other solution than the one on After Unlock event. 

    Follow below steps

    1. Create new JavaScript method (name : ARAS_Community_JS)and add below code 

    Update Server Method Name below ARAS_Community_Server

    var dlvAssignedTo = document.thisItem.getProperty('dlv_assignedto');
    if (dlvAssignedTo)
    {
    if (!top.aras.confirm('Do you want to send mail to DLV Assigned to User ?'))
    {
    return;
    }
    var callServerMethod = aras.IomInnovator.newItem('Method', 'ARAS_Community_Server');
    callServerMethod.setProperty('dlv_assignedto', dlvAssignedTo);
    callServerMethod.setProperty('item_number', document.thisItem.getProperty('item_number'));
    var result = callServerMethod.apply();
    if (result.isError())
    {
    aras.AlertError(result.getErrorString());
    }
    else
    {
    aras.AlertSuccess('Email sent successfully.');
    }
    }

    2. Update your existing server method with below code

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

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

    //Get Url
    string str_actionID = this.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;

    3. Open form where this dlv_assignedto property exist

    4. Add Form field event on dlv_assignedto property (Method Name : ARAS_Community_JS and event : On Change)

    5. Save and Unlock Form

    6. Try testing.

    Expected Result:

    Whenever the dlv_assigned_to field is changed, it will ask for confirmation from user whether to send email to user, if user select Ok, then it will send email else it will not send email

12 Replies

  • 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

    • yanjim's avatar
      yanjim
      Ideator I

      Hi Gopikrishnan,

      Thank you for your kindly reply!

      I did not get any error from Aras GUI, just did not get any email when using onAfterUnlock.

      But from the log file, I found following:

      <LOGFILE>
      <event time="2020-06-03 20:51:56Z" reason="soap_action" TickCount="113254250" dt="0" message="ApplyItem" />
      <event time="2020-06-03 20:51:56Z" reason="requestDom" TickCount="113254250" dt="0" />
      <SOAP-ENV:Envelope xmlns:SOAP-ENV="">schemas.xmlsoap.org/.../">
      <SOAP-ENV:Body>
      <ApplyItem>
      <Item type="DLV_ActionReq" id="F9732A7FC25144A481100EDF91582DB1" action="unlock" />
      </ApplyItem>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>
      <event time="2020-06-03 20:51:56Z" reason="cachedriver-key" TickCount="113254265" dt="15" message="GetMethodFromCache:A1C22425BF134F46833FA6E8AAA21348:en" />
      <event time="2020-06-03 20:51:56Z" reason="cachedriver-value" TickCount="113254265" dt="0" message="Aras.Server.Core.CacheMethodInfo" />
      <event time="2020-06-03 20:51:56Z" reason="NewID" TickCount="113254265" dt="0" message="1563BFE4DA9245299CAD37B38DFF1BF6" />
      <event time="2020-06-03 20:51:56Z" reason="cachedriver-key" TickCount="113254500" dt="235" message="GetItemTypeIdFromCache:Email Message:en" />
      <event time="2020-06-03 20:51:56Z" reason="cachedriver-value" TickCount="113254500" dt="0" message="Aras.Server.Core.ItemTypeIdInfo" />
      <event time="2020-06-03 20:51:56Z" reason="cachedriver-key" TickCount="113254500" dt="0" message="GetServerEventsFromCache:F91DE6AE038A4CC8B53D47D5A7FA49FC:en" />
      <event time="2020-06-03 20:51:56Z" reason="cachedriver-value" TickCount="113254500" dt="0" message="Aras.Server.Core.MetaDataInfo.ServerEventsList" />
      <event time="2020-06-03 20:51:56Z" reason="cachedriver-key" TickCount="113254500" dt="0" message="GetRelListFromCache:F91DE6AE038A4CC8B53D47D5A7FA49FC:False:en" />
      <event time="2020-06-03 20:51:56Z" reason="cachedriver-value" TickCount="113254500" dt="0" message="Aras.Server.Core.RelTypesList" />
      <event time="2020-06-03 20:51:56Z" reason="cachedriver-key" TickCount="113254500" dt="0" message="AllowedPermissionsList:F91DE6AE038A4CC8B53D47D5A7FA49FC:en" />
      <event time="2020-06-03 20:51:56Z" reason="cachedriver-value" TickCount="113254500" dt="0" message="Aras.Server.Core.PermissionsList" />
      <event time="2020-06-03 20:51:56Z" reason="performance" TickCount="113254500" dt="0" message="250" />
      <event time="2020-06-03 20:51:56Z" reason="responseDom" TickCount="113254500" dt="0" />
      <SOAP-ENV:Envelope xmlns:SOAP-ENV="">schemas.xmlsoap.org/.../">
      <SOAP-ENV:Body>
      <Result>
      <Item type="DLV_ActionReq" typeId="B860EC10B74C40C089BA76FC4C41B26C" id="F9732A7FC25144A481100EDF91582DB1">
      <classification>Internal</classification>
      <config_id keyed_name="ACT-00000015" type="DLV_ActionReq">F9732A7FC25144A481100EDF91582DB1</config_id>
      <created_by_id keyed_name="Admin: Jimmi Yang" type="User">17E2112E82C745DCA979A95EB4B030C2</created_by_id>
      <created_on>2020-06-02T16:23:38</created_on>
      <current_state name="Created" keyed_name="Created" type="Life Cycle State">70ADED32721B485982F4446B3B7CCB05</current_state>
      <dlv_assignedto keyed_name="Jimmi Yang" type="User">BA68B9B4A8AF4EA2B255B5D1AB0C9E25</dlv_assignedto>
      <dlv_create_edit_usr>0</dlv_create_edit_usr>
      <dlv_customer keyed_name="Admin: Jimmi Yang" type="User">17E2112E82C745DCA979A95EB4B030C2</dlv_customer>
      <dlv_description>fdgdfgsfsfdsdf</dlv_description>
      <dlv_effectmanual>1</dlv_effectmanual>
      <dlv_estwork>Hours</dlv_estwork>
      <dlv_ext_usr>0</dlv_ext_usr>
      <dlv_header>fgdfg update</dlv_header>
      <dlv_int_usr>0</dlv_int_usr>
      <dlv_prio>Low</dlv_prio>
      <dlv_requested_by keyed_name="Admin: Jimmi Yang" type="User">17E2112E82C745DCA979A95EB4B030C2</dlv_requested_by>
      <dlv_searchdata_usr>0</dlv_searchdata_usr>
      <dlv_status>Received</dlv_status>
      <dlv_taskcategory>Maintain Data</dlv_taskcategory>
      <dlv_upload_doc_usr>0</dlv_upload_doc_usr>
      <generation>1</generation>
      <id keyed_name="ACT-00000015" type="DLV_ActionReq">F9732A7FC25144A481100EDF91582DB1</id>
      <is_current>1</is_current>
      <is_released>0</is_released>
      <keyed_name>ACT-00000015</keyed_name>
      <major_rev>A</major_rev>
      <modified_by_id keyed_name="Admin: Jimmi Yang" type="User">17E2112E82C745DCA979A95EB4B030C2</modified_by_id>
      <modified_on>2020-06-03T14:36:35</modified_on>
      <new_version>1</new_version>
      <not_lockable>0</not_lockable>
      <permission_id keyed_name="DLV_New" type="Permission">80A688D56E2D42B0A210E0D083196B97</permission_id>
      <state>Created</state>
      <team_id keyed_name="DL Process" type="Team">915EAEE1BC2845848C6F551E2AADCC21</team_id>
      <item_number>ACT-00000015</item_number>
      </Item>
      </Result>
      <Message>
      <event name="ids_modified" value="F9732A7FC25144A481100EDF91582DB1" />
      </Message>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>
      <event time="2020-06-03 20:51:56Z" reason="soap_action" TickCount="113254562" dt="0" message="ApplyItem" />
      <event time="2020-06-03 20:51:56Z" reason="requestDom" TickCount="113254562" dt="0" />
      <SOAP-ENV:Envelope xmlns:SOAP-ENV="">schemas.xmlsoap.org/.../">
      <SOAP-ENV:Body>
      <ApplyItem>
      <Item type="ItemType" action="get" select="id, name, label">
      <Relationships>
      <Item type="Morphae" action="get" select="id">
      <related_id>B860EC10B74C40C089BA76FC4C41B26C</related_id>
      </Item>
      </Relationships>
      </Item>
      </ApplyItem>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>
      <event time="2020-06-03 20:51:56Z" reason="performance" TickCount="113254562" dt="0" message="0" />
      <event time="2020-06-03 20:51:56Z" reason="responseDom" TickCount="113254562" dt="0" />
      <SOAP-ENV:Envelope xmlns:SOAP-ENV="">schemas.xmlsoap.org/.../">
      <SOAP-ENV:Body>
      <SOAP-ENV:Fault xmlns:af="">www.aras.com/InnovatorFault">
      <faultcode>0</faultcode>
      <faultstring><![CDATA[No items of type ItemType found.]]></faultstring>
      <detail>
      <af:legacy_detail><![CDATA[No items of type ItemType found.]]></af:legacy_detail>
      <af:legacy_faultstring><![CDATA[No items of type 'ItemType' found using the criteria:
      <Item type="ItemType" action="get" select="id, name, label"><Relationships><Item type="Morphae" action="get" select="id"><related_id>B860EC10B74C40C089BA76FC4C41B26C</related_id></Item></Relationships></Item>
      ]]></af:legacy_faultstring>
      <af:legacy_faultactor> at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
      at System.Environment.get_StackTrace()
      at Aras.Server.Core.XML.SetErrorMessageImplementation(XmlDocument xmlDom, String faultCode, String faultString, String legacyFaultString, String stackTrace) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\Xml\xml.cs:line 662
      at Aras.Server.Core.XML.Aras.Server.Core.IXml.SetErrorMessage(XmlDocument xmlDom, XmlQualifiedName faultCode, String faultString, String legacyFaultString) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\Xml\xml.cs:line 195
      at Aras.Server.Core.GetItemProxy.SetNoItemsFoundFaultCode(XmlDocument dom, String itemTypeName, XmlNode criteriaNode) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\GetItem\GetItem.cs:line 623
      at Aras.Server.Core.GetItemProxy.GetItem_DefaultImplementation(XmlElement item, XmlDocument inDom, XmlDocument outDom, ItemTypeInfo itemType, Boolean maxGeneration, Boolean forceIgnorePermissions, InnovatorDBCommandParameterCollection pars, Int32 curLevel, Int32 maxLevel) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\GetItem\GetItem.cs:line 1734
      at Aras.Server.Core.GetItemProxy.GetItem_Implementation(XmlElement criteriaItem, Boolean maxGeneration, Int32 curLevel, Int32 maxLevel, Boolean forceIgnorePermissions, XmlDocument outDom) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\GetItem\GetItem.cs:line 1628
      at Aras.Server.Core.GetItemProxy.GetItemInternal(XmlDocument itemDom, XmlDocument passedResponseDom) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\GetItem\GetItem.cs:line 700
      at Aras.Server.Core.ApplyItemProxy.ApplyItem(XmlDocument&amp; inDom, AddItemImplementationAdditionalInfo additionalItemInfo, XmlDocument&amp; outDom) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\ApplyItem.cs:line 562
      at Aras.Server.Core.ApplyItemProxy.Aras.Server.Core.IApplyItem.ApplyItem(XmlDocument inDom, XmlDocument outDom) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\ApplyItem.cs:line 284
      at Aras.Server.Core.ApplySoapAction.Apply(String soapAction, XmlDocument inDom, XmlDocument outDom, Boolean securityCheck) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\ApplySoapAction.cs:line 130
      at Aras.Server.Core.SoapActionRequestController.ProcessSoapAction(String soapAction, XmlDocument requestDom) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\RequestControllers\SoapActionRequestController.cs:line 263
      at Aras.Server.Core.SoapActionRequestController.GetResponse() in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\RequestControllers\SoapActionRequestController.cs:line 105
      at Aras.Server.Core.SoapActionRequestController.ProcessRequest() in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\RequestControllers\SoapActionRequestController.cs:line 57
      at Aras.Server.Core.Startup.InnovatorServerMain() in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\Startup.cs:line 27
      at Aras.Web.Server.InnovatorServer.OnLoad(EventArgs e) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Aras.Web.Server\InnovatorServer.cs:line 17
      at System.Web.UI.Control.LoadRecursive()
      at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      at System.Web.UI.Page.ProcessRequest()
      at System.Web.UI.Page.ProcessRequest(HttpContext context)
      at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
      at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
      at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)
      at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)
      at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)
      at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
      at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
      at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
      at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus&amp; notificationStatus)
      at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus&amp; notificationStatus)
      at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
      at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)</af:legacy_faultactor>
      </detail>
      </SOAP-ENV:Fault>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>
      <event time="2020-06-03 20:51:56Z" reason="soap_action" TickCount="113254750" dt="0" message="ApplyItem" />
      <event time="2020-06-03 20:51:56Z" reason="requestDom" TickCount="113254750" dt="0" />
      <SOAP-ENV:Envelope xmlns:SOAP-ENV="">schemas.xmlsoap.org/.../">
      <SOAP-ENV:Body>
      <ApplyItem>
      <Item type="DLV_ActionReq_File" action="get" page="1" select="id,created_by_id,created_on,modified_by_id,modified_on,locked_by_id,major_rev,css,current_state,keyed_name,related_id(comments,file_type,indexed_on,created_by_id,created_on,modified_by_id,modified_on,locked_by_id,major_rev,css,current_state,keyed_name),source_id" pagesize="" returnMode="itemsOnly">
      <source_id condition="eq">F9732A7FC25144A481100EDF91582DB1</source_id>
      </Item>
      </ApplyItem>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>
      <event time="2020-06-03 20:51:56Z" reason="performance" TickCount="113254765" dt="15" message="15" />
      <event time="2020-06-03 20:51:56Z" reason="responseDom" TickCount="113254765" dt="0" />
      <SOAP-ENV:Envelope xmlns:SOAP-ENV="">schemas.xmlsoap.org/.../">
      <SOAP-ENV:Body>
      <SOAP-ENV:Fault xmlns:af="">www.aras.com/InnovatorFault">
      <faultcode>0</faultcode>
      <faultstring><![CDATA[No items of type DLV_ActionReq_File found.]]></faultstring>
      <detail>
      <af:legacy_detail><![CDATA[No items of type DLV_ActionReq_File found.]]></af:legacy_detail>
      <af:legacy_faultstring><![CDATA[No items of type 'DLV_ActionReq_File' found using the criteria:
      <Item type="DLV_ActionReq_File" action="get" page="1" select="id,created_by_id,created_on,modified_by_id,modified_on,locked_by_id,major_rev,css,current_state,keyed_name,related_id(comments,file_type,indexed_on,created_by_id,created_on,modified_by_id,modified_on,locked_by_id,major_rev,css,current_state,keyed_name),source_id" pagesize="" returnMode="itemsOnly"><source_id condition="eq">F9732A7FC25144A481100EDF91582DB1</source_id></Item>
      ]]></af:legacy_faultstring>
      <af:legacy_faultactor> at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
      at System.Environment.get_StackTrace()
      at Aras.Server.Core.XML.SetErrorMessageImplementation(XmlDocument xmlDom, String faultCode, String faultString, String legacyFaultString, String stackTrace) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\Xml\xml.cs:line 662
      at Aras.Server.Core.XML.Aras.Server.Core.IXml.SetErrorMessage(XmlDocument xmlDom, XmlQualifiedName faultCode, String faultString, String legacyFaultString) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\Xml\xml.cs:line 195
      at Aras.Server.Core.GetItemProxy.SetNoItemsFoundFaultCode(XmlDocument dom, String itemTypeName, XmlNode criteriaNode) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\GetItem\GetItem.cs:line 623
      at Aras.Server.Core.GetItemProxy.GetItem_DefaultImplementation(XmlElement item, XmlDocument inDom, XmlDocument outDom, ItemTypeInfo itemType, Boolean maxGeneration, Boolean forceIgnorePermissions, InnovatorDBCommandParameterCollection pars, Int32 curLevel, Int32 maxLevel) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\GetItem\GetItem.cs:line 1734
      at Aras.Server.Core.GetItemProxy.GetItem_Implementation(XmlElement criteriaItem, Boolean maxGeneration, Int32 curLevel, Int32 maxLevel, Boolean forceIgnorePermissions, XmlDocument outDom) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\GetItem\GetItem.cs:line 1628
      at Aras.Server.Core.GetItemProxy.GetItemInternal(XmlDocument itemDom, XmlDocument passedResponseDom) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\GetItem\GetItem.cs:line 700
      at Aras.Server.Core.ApplyItemProxy.ApplyItem(XmlDocument&amp; inDom, AddItemImplementationAdditionalInfo additionalItemInfo, XmlDocument&amp; outDom) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\ApplyItem.cs:line 562
      at Aras.Server.Core.ApplyItemProxy.Aras.Server.Core.IApplyItem.ApplyItem(XmlDocument inDom, XmlDocument outDom) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\ApplyItem.cs:line 284
      at Aras.Server.Core.ApplySoapAction.Apply(String soapAction, XmlDocument inDom, XmlDocument outDom, Boolean securityCheck) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\ApplySoapAction.cs:line 130
      at Aras.Server.Core.SoapActionRequestController.ProcessSoapAction(String soapAction, XmlDocument requestDom) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\RequestControllers\SoapActionRequestController.cs:line 263
      at Aras.Server.Core.SoapActionRequestController.GetResponse() in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\RequestControllers\SoapActionRequestController.cs:line 105
      at Aras.Server.Core.SoapActionRequestController.ProcessRequest() in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\RequestControllers\SoapActionRequestController.cs:line 57
      at Aras.Server.Core.Startup.InnovatorServerMain() in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Core\Startup.cs:line 27
      at Aras.Web.Server.InnovatorServer.OnLoad(EventArgs e) in E:\Builds\Innovator_RELS11-0-SP12\6920-RELS11-0-SP12\Innovator.git\CompilableCode\Aras.Web.Server\InnovatorServer.cs:line 17
      at System.Web.UI.Control.LoadRecursive()
      at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      at System.Web.UI.Page.ProcessRequest()
      at System.Web.UI.Page.ProcessRequest(HttpContext context)
      at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
      at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
      at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)
      at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)
      at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)
      at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
      at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
      at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
      at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus&amp; notificationStatus)
      at System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus&amp; notificationStatus)
      at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
      at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)</af:legacy_faultactor>
      </detail>
      </SOAP-ENV:Fault>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>
      <event time="2020-06-03 20:51:56Z" reason="soap_action" TickCount="113254890" dt="0" message="applyaml" />
      <event time="2020-06-03 20:51:56Z" reason="requestDom" TickCount="113254890" dt="0" />
      <AML>
      <Item type="RelationshipType" action="get" select="name,label,auto_search,copy_permissions,core,default_page_size,description,grid_view,hide_in_all,inc_rel_key_name,inc_related_key_name,is_list_type,max_occurs,min_occurs,new_show_related,related_notnull,related_option,create_related,use_src_access,source_id,relationship_id,related_id" related_expand="0" isCriteria="0">
      <id>Parameters</id>
      <Relationships>
      <Item type="Relationship View" action="get" select="form,grid,start_page,parameters,related_id" related_expand="0" isCriteria="0" />
      <Item type="Relationship Grid Event" action="get" select="grid_event,related_id(name,method_type,method_code)" isCriteria="0" />
      </Relationships>
      </Item>
      </AML>
      <event time="2020-06-03 20:51:56Z" reason="soap_action" TickCount="113254937" dt="0" message="ApplyItem" />
      <event time="2020-06-03 20:51:56Z" reason="requestDom" TickCount="113254937" dt="0" />
      <SOAP-ENV:Envelope xmlns:SOAP-ENV="">schemas.xmlsoap.org/.../">
      <SOAP-ENV:Body>
      <ApplyItem>
      <Item isNew="1" isTemp="1" type="SQL" action="DLV_COUNTS_ON_TABS_SERVER">
      <relshipTypeName>DLV_ActionReq_File|DLV_ActionReq_ActionReq|DLV_ActionReq_RefBy|DLV_ActionReq_Subscribers|DLV_ActionReq_User</relshipTypeName>
      <id>F9732A7FC25144A481100EDF91582DB1</id>
      </Item>
      </ApplyItem>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>
      <event time="2020-06-03 20:51:56Z" reason="SQL Process inDom" TickCount="113254937" dt="0" />
      <Item isNew="1" isTemp="1" type="SQL" action="SQL PROCESS">
      <name>dlv_cnt_tab_rels</name>
      <PROCESS>CALL</PROCESS>
      <ARG1>F9732A7FC25144A481100EDF91582DB1</ARG1>
      <ARG2>DLV_ActionReq_File|DLV_ActionReq_ActionReq|DLV_ActionReq_RefBy|DLV_ActionReq_Subscribers|DLV_ActionReq_User</ARG2>
      </Item>
      <event time="2020-06-03 20:51:56Z" reason="SQL Process db_item" TickCount="113254937" dt="0" />
      <Item isNew="1" isTemp="1" type="SQL" action="SQL PROCESS">
      <name>dlv_cnt_tab_rels</name>
      <PROCESS>CALL</PROCESS>
      <ARG1>F9732A7FC25144A481100EDF91582DB1</ARG1>
      <ARG2>DLV_ActionReq_File|DLV_ActionReq_ActionReq|DLV_ActionReq_RefBy|DLV_ActionReq_Subscribers|DLV_ActionReq_User</ARG2>
      </Item>
      <event time="2020-06-03 20:51:56Z" reason="SQL Process outDom" TickCount="113254937" dt="0" />
      <SOAP-ENV:Envelope xmlns:SOAP-ENV="">schemas.xmlsoap.org/.../">
      <SOAP-ENV:Body>
      <Result>
      <Item>
      <ant>0|0|0|0|0|</ant>
      </Item>
      </Result>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>
      <event time="2020-06-03 20:51:56Z" reason="performance" TickCount="113254937" dt="0" message="0" />
      <event time="2020-06-03 20:51:56Z" reason="responseDom" TickCount="113254937" dt="0" />
      <SOAP-ENV:Envelope xmlns:SOAP-ENV="">schemas.xmlsoap.org/.../">
      <SOAP-ENV:Body>
      <Result>
      <Item>
      <ant>0|0|0|0|0|</ant>
      </Item>
      </Result>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>

    • yanjim's avatar
      yanjim
      Ideator I

      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

      • Gopikrishnan's avatar
        Gopikrishnan
        Ideator I

        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

  • Hi Jimmi,

    I'm not sure a field event is the best option for this particular use case. The changes that are made within the form are only suggestions until the user clicks the save button to write those changes to the database. The onChange field event triggers when the actual field is filled in and not when the property is changed at a database level. In a situation where a user accidentally clicks on the wrong user when filling in the field and then corrects their mistake before clicking save, the wrong user will still get a notification that a task was assigned to them even though it isn't.

    For that reason, this use case is likely best handled server-side. If there is a Workflow or Life Cycle attached to this item, you could configure those to send an email without needing to write any extra code. If there's not, this is probably best done in an onBeforeUpdate server event where you can query for the old value of the div_assignedto property to check if it's being changed, and then send the email if it is.

    Chris


    Christopher Gillis

    Aras Labs Software Engineer

    • yanjim's avatar
      yanjim
      Ideator I

      Hi Chris,

      Agree! But I couldn't get the old value of div_assignedto to work, can you help me with that? See my reply 2020-06-12, 5 pm

      /Jimmi

      • christopher_gillis's avatar
        christopher_gillis
        New Member

        I think the issue was the type of server method being used previously. onAfterUnlock events aren't typically used, and I think by the time that event would be called, the value at a database level will have already been changed.

        An onBeforeUpdate event should contain the old value which you can get from the database and the new value (if one exists) within the context item of this. By comparing these two values, you should be able to determine if an email is necessary.

        This code I copied from above should work fine in a different event type:

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

        // Get the existing assignee
        Item thisItem = inn.newItem(this.getType(), "get");
        thisItem.setAttribute("select", "dlv_assignedto,item_number");
        thisItem.setID(this.getID());
        thisItem = thisItem.apply();
        string existingAssignee = thisItem.getProperty("dlv_assignedto","");

        if((newAssignee != "") && (newAssignee == existingAssignee))
        {
        return this;
        }

        I've switched the variable names around for better clarity. Since this will contain the proposed changes before they are sent to the database, we set that to newAssignee, and then we query for the item as it exists in the database before the change to find the existing value. I've also added in an additional check in bold to see if there is even a change being made to the div_assignedto property at all.

        Lastly, I'd recommend seeing if a Workflow or Life Cycle could be added to your use case instead of custom code like this. I could see a simple life cycle like the one below being added to this ItemType:

        Proposed->In Work->Completed

        A task request comes in and starts in the Proposed state. It could be looked at and reviewed in this state, and then assigned to a specific person before being voted into the In Work state. At that point, the person assigned to the task via the div_assignedto property is emailed. This kind of notification can be configured directly on the Life Cycle Map, so you won't need to write any custom code at all. 

        Chris