Solved

Workflow Error - Send email

  • 13 June 2017
  • 2 replies
  • 21 views

Badge +8

Hi there.  

 

So, I'm in the process of shoring up a workflow to automate it's starting.  In the current state, someone clicks a button on a form every hour and then checks the workflow URL to ensure that the workflow runs properly. 

 

99% of the time it runs without a hitch, but the workflow does execute a database stored procedure as part of the flow, and sometimes the stored procedure fails, thus causing the workflow to fail and stop.

 

What I'm thinking would be logical would be a way to have a line rule from the "Execute Stored Procedure" activity to an "Email" activity that would kick off when the workflow errors at that activity.  Otherwise, the other line would take it to the next activity in the flow.  

 

I'm not seeing a way to do that, however.  Does anyone have any ideas?  The K2 documentation on exception rules does not seem super helpful...

 

Thanks,

 

Rob

 

 

icon

Best answer by Kran 13 June 2017, 12:58

View original

2 replies

Badge +9

Hi Robert,

 

You can achieve this using one of below technique :

 

1) In SQL procedure use try catch to detect the exception on success execution send string “Success” and on exception send string “failure”

In your workflow take two parallel lines connect one line with you default activity (having line rule to check if stored procedure return success string) and another line with new activity having email Event(having line rule to check if stored procedure return failure string).

Now if you’re Stored Procedure fails because of Exception block it will return “failure” string and line rule force flow to send email.

 

 

 2) You can use code in Exception rule to send email.

             System.Net.Mail.SmtpClient MailServer = new System.Net.Mail.SmtpClient(K2.StringTable["Mail Server"]);

            from = “from Address";

            to = "to address";

            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);

            message.Body = "Exception occurred";

            message.Subject = "Task Failure Notification ";

            MailServer.Send(message);

 

 

let me know if this helps you.

Badge +8

I think both of these solutions will work well!  It would be BETTER if K2 had some kind of "if error" line rules built in, but these will also work.

 

Thanks much, 

 

Rob

 

 

Reply