I want to be informed if an Umbraco Forms workflow fails on a particular client's website (Umbraco 8.18.13 / Forms 8.13.14) so I've written a simple event handler to send an email if a workflow fails but it doesn't seem to be firing. Does anyone else have any experience of using this and getting it to work?
Here is my simple event handler component which is registered using a composer class:
public class FormsWorkflowFailedComponent : IComponent
{
private readonly IWorkflowServices _workflowServices;
public FormsWorkflowFailedComponent(IWorkflowServices workflowServices)
{
_workflowServices = workflowServices;
}
public void Initialize()
{
_workflowServices.WorkflowFailed += WorkflowServices_WorkflowFailed;
}
private void WorkflowServices_WorkflowFailed(object sender, Umbraco.Forms.Core.WorkflowEventArgs e)
{
try
{
var emailHelper = new EmailHelper();
var messageLines = new List<string>()
{
"A workflow failed to run:" + Environment.NewLine,
"Workflow Name: " + e.Workflow.Name,
"Form: " + e.Workflow.Form.ToString()
};
var emailTo = ConfigurationManager.AppSettings["WorkfailFailedNotification.EmailAddress"] ?? "";
if (!string.IsNullOrEmpty(emailTo))
emailHelper.SendEmail(string.Join(Environment.NewLine, messageLines), emailHelper.GetDefaultSenderEmail(), emailTo, "Workflow failed",
loadTemplate: false, isHtml: false);
}
catch
{
}
}
public void Terminate()
{
_workflowServices.WorkflowFailed -= WorkflowServices_WorkflowFailed;
}
}
I then wrote a simple Umbraco Forms custom workflow which simulates a workflow failure by only ever returning WorkflowExecutionStatus.Failed from the Execute method.
When running this, if I add a breakpoint to the Initialize() method of the component the breakpoint is hit and the event handler is registered. However, if I add a breakpoint to the WorkflowServices_WorkflowFailed event handler method it is never hit when a workflow returns a failed status.
Event handler for workflow failed event
Hi,
I want to be informed if an Umbraco Forms workflow fails on a particular client's website (Umbraco 8.18.13 / Forms 8.13.14) so I've written a simple event handler to send an email if a workflow fails but it doesn't seem to be firing. Does anyone else have any experience of using this and getting it to work?
Here is my simple event handler component which is registered using a composer class:
I then wrote a simple Umbraco Forms custom workflow which simulates a workflow failure by only ever returning WorkflowExecutionStatus.Failed from the Execute method.
When running this, if I add a breakpoint to the Initialize() method of the component the breakpoint is hit and the event handler is registered. However, if I add a breakpoint to the WorkflowServices_WorkflowFailed event handler method it is never hit when a workflow returns a failed status.
Any help appreciated, thanks!
is working on a reply...