Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark 4 posts 95 karma points
    Jul 01, 2016 @ 09:51
    Mark
    0

    Handling Workflow Failure

    I've developed a custom workflow to submit form data to a third party system. This submission can either succeed or fail and in the event of a failure it is important to let the user know it has not succeeded. I notice on the workflow's Execute method I can set WorkflowExecutionStatus.Failed in the event that the third party system does not accept the data but there doesn't seem to be any obvious way to handle this failure.

    Ideally what I'd like is to either redirect the user back to the form and pop an error message, or even redirect them to a different page than the page specified in the "On Submit" dialog.

    Any ideas?

  • Nick Frederiksen 18 posts 77 karma points
    Jul 08, 2016 @ 11:04
    Nick Frederiksen
    0

    Hi Mark,

    I might have an idea. I haven't tried it myself but it might work for you.

    You could try to subscribe to the "WorkflowFailed"-event:

    Umbraco.Forms.Core.Services.WorkflowService.WorkflowFailed
    

    This would fire whenever a workflow has failed.

    I don't know whether or not you have access to the same HttpContext as the posted form from that event. I do know, however, that you do not have access to the record data from the event.

    To subscribe to that event, I usually do it in the Global.asax file:

    public class Global : UmbracoApplication
    {
        protected override void OnApplicationStarted(object sender, EventArgs e)
        {
            WorkflowService.WorkflowFailed += WorkflowService_WorkflowFailed;
            base.OnApplicationStarted(sender, e);
        }
    
        private void WorkflowService_WorkflowFailed(object sender, Umbraco.Forms.Core.WorkflowEventArgs e)
        {
            // TODO: Handle error
        }
    }
    

    Let me know if it works.

  • Mark 4 posts 95 karma points
    Jul 08, 2016 @ 11:08
    Mark
    100

    Hi Nick,

    Thanks for the reply. I wasn't aware of the workflow failed event! I've already got a workaround in place whereby I add some info to the session cache (form id, record id) if it fails, using a special "WorkflowErrored" key and then I've used route hijacking on the success page to check for this value and handle appropriately.

    I will check out the workflow failed event for next time though!

    Thanks, Mark

  • Nick Frederiksen 18 posts 77 karma points
    Jul 08, 2016 @ 11:22
    Nick Frederiksen
    0

    Good to hear you found a workaround.

    Please let me know if you try the event and if it helped.

  • IBS 1 post 71 karma points
    May 31, 2018 @ 11:51
    IBS
    0

    For reference to anyone on Forms 7.0, we are just overwriting the e.Form.GoToPageOnSubmit in our workflow to redirect to a 'failed' page (as we still capture the data on error and insert it into a different table).

    One caveat is that we have our workflow last in the list and have the workflows running synchronously.

  • Mark Bowser 260 posts 845 karma points c-trib
    Apr 12, 2019 @ 20:29
    Mark Bowser
    0

    Any idea how to get e.Form.MessageOnSubmit work? I thought I had it working at one point, but I must be crazy because I can't seem to get any message I set on any workflow to override the message set on the default "Submit message / Go to page" workflow.

Please Sign in or register to post replies

Write your reply to:

Draft