How would one retrieve the 'to', 'from', ''subject', 'hmlVar' values of an activiti mailtask via either a 'java class start or end listener on the given mailtask? If notpossible, what ate the alternatives? I am able to capture an email failure with use of the ignoreexception setting, but i need to identfy the pertinent elements fo the given problematic email.
Solved! Go to Solution.
Thanks jmzags _ ,
That helps. I see that you are using an ExecutionListener on the Email Task. You can get properties "to", "from", "subject", etc. in the mail task within this execution listener.
You can retrieve process definition xml from the execution. Then you can parse the xml and retrieve those mail properties.
I have attached a simple unit test to retrieve process definition xml from an mail task execution listener.
Hope this helps,
Thanks,
Thong Huynh
bp3
Hi jmzags _ ,
Reading your question, I think you're asking "if my email task fails, I'd like to capture its details".
The email task is pretty simple as is right now.
So I'd recommend you to write up your own Email Task class using Java Service Task and implement error handling patterns within. With your own Email Task, you'd have total control over the email task, its configuration settings and how it should behave if errors occur.
In your case, what problems are you having with Email Task out-of-the-box?
Thanks,
Thong Huynh
Hello Thong
Yes, I could replace the existing out of the box nail tasks but I'm looking to minimize the level of effort for addressing an issue at hand (which I'll explain momentarily). There are multiple workflow templates, each with multiple email tasks, for which I need to work with. They all currently implement the same start and end listeners to perform various actions. I thought I would be able to update one listener to capture the desired data for further processing. So, I'm not clear if you are saying it is not possible to capture this data?
To your question on what the issue is that is driving this question.........
The mail tasks are sporadically failing and thus rolling back to the previous user task. The failures are attributed to mailhost being unavailable ( usually too busy).. I have no control on the mailhost availability, I've been told by IT to simply re-send. The retry is set to the default 3, but even that on occasions is not enough . To avoid the rollback effect of a failed mailtask, I've set the ignoreException to true and I am capturing the error msg thrown in the post task listener, where I subsequently send an email (via a database procedure call with task variable inputs) to the admin notifying about the email failure. But, the desire is to successfully send the intended email .
My use of the ignoreException has actually made a bad situation worse, as it appears if first attempt fails there are no retries.
Perhaps there is a way to increase the retries, specific to the given task, if it fails after the default 3? But I would still ultimately need to have the ignoreexception kick in if the max retries is hit to gracefully
handle the final failure and allow flow to move on to next usertask. Any ideas on how I would approach that or any other suggestions aside from using a different means of sending Emails?
thanks
Thanks jmzags _
Awesome response! Appreciate it. I understand your use case now. Let me try some experiments on my end and I will get back to you.
Meanwhile,
There are multiple workflow templates, each with multiple email tasks, for which I need to work with. They all currently implement the same start and end listeners to perform various actions. I thought I would be able to update one listener to capture the desired data for further processing. So, I'm not clear if you are saying it is not possible to capture this data?
It would be super helpful if you can create a unit test that represents your current implementation (I'm not quite getting it based on this description e.g. what are start and end listeners? what do you mean by updating a listener? etc.).
Thank you,
Thong
bp3
Hi Thong
Thanks very much for following up.....
Here is an example of a typical the out of the box mailtask in use, which reflects the use of the ignoreexceotion variable and error message variable......
<serviceTask id="mailtask" name="Mgr Review Mail" activiti:type="mail">
<extensionElements>
<activiti:field name="ignoreException">
<activiti:string><![CDATA[true]]></activiti:string>
</activiti:field>
<activiti:field name="exceptionVariableName">
<activiti:string><![CDATA[emailErr]]></activiti:string>
</activiti:field>
<activiti:field name="from">
<activiti:string><![CDATA[Workflows@xxxxxxxxx.com]]></activiti:string>
</activiti:field>
<activiti:field name="subject">
<activiti:expression><![CDATA[${key2} ${key1} - Review for Completeness ]]></activiti:expression>
</activiti:field>
<activiti:field name="to">
<activiti:expression><![CDATA[${EMAIL_LIST}]]></activiti:expression>
</activiti:field>
<activiti:field name="html">
<activiti:expression><![CDATA[<br>
You have been assigned a MGR Review for Completeness task for ${key2} ${key1} <br><br>
<b>Description:</b><br>
${CN_DESC} <br><br>
Log onto <A href=" ${pdmURL}">Web</A> and look for this task.<br><br>
Please do not respond to this email.]]></activiti:expression>
</activiti:field>
<activiti:executionListener event="start" class="org.activiti.custom.PreEmailTaskListener"></activiti:executionListener>
<activiti:executionListener event="end" class="org.activiti.custom.PostEmailTaskListener"></activiti:executionListener>
</extensionElements>
</serviceTask>
Here is a snippet of the post email task listener currently in place, which uses a database procedure call to send an email to the admins with the email error msg that was thrown.
The desire is to also get the mailtask retries to occur at this point or be able to send the 'To', 'From','Subject', and htmlVar info to the db procedure as well
thanks,
jmzags
Thanks jmzags _ ,
That helps. I see that you are using an ExecutionListener on the Email Task. You can get properties "to", "from", "subject", etc. in the mail task within this execution listener.
You can retrieve process definition xml from the execution. Then you can parse the xml and retrieve those mail properties.
I have attached a simple unit test to retrieve process definition xml from an mail task execution listener.
Hope this helps,
Thanks,
Thong Huynh
bp3
Thong
Thank you for your response.
Given the significant number of email tasks in a given workflow and the level of effort to implement the suggestion of parsing the xml to retrieve the desired data, I have decided to replace the Activiti out-of-the-box mail task with execution listeners to send email
thanks
Ask for and offer help to other Alfresco Process Services and Activiti Users and members of the Alfresco team.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.