+44(0)1908 545 770
YOUR EXPERT RPA PARTNER

Team up with our RPA strategy and tech specialists for maximum automation impact

Find out more
Harness the power of UiPath in your business.
WATCH NOW

Save money and spend more time on priority work.

Book consultation
READY, SET, AUTOMATE

Let's choose, design and deploy a process automation solution for your business.

Find out more
TRANSFORM YOUR BUSINESS

Let's analyse your business to discover opportunities for innovation and automation.

Find out more

Begin your business transformation journey

Book consultation
AUTOMATE EVERY FUNCTION

Automate where it matters most. Scale to solve challenges in every area

Find out more
GIVE EVERY TEAM THE TOOLS FOR SUCCESS

Equip people with user-friendly solutions that save time and make work easier

Find out more

Which business problem
can we solve first?

Book consultation
02 July 2014

K2 and .NET Transactions

I spent some time today to apply some changes to a system Velocity IT and K2 built for a UK defence customer.

K2 blackearl is used for this workflow solution and ASP.NET is used as the UI (user interface) technology.  The SourceCode.Workflow.Client .NET assembly is used to integrate the UI and the workflow.

K2 Automated Testing Software

BenchQA allows full test automation of K2, including fully automated K2 SmartForms and K2 Workflow testing. It promotes test driven development for K2 and ensures continued quality assurance for K2 solutions. Easily apply changes to test cases to accommodate changes to K2 apps and ensure all apps are regression tested to avoid defects and assure continuous quality.

 

Free K2 Five Upgrade Review

The interesting part of this process is the use of System.Transactions to ensure all individual UI and K2 operations complete successfully to ensure the overall success of the transaction.  One unwanted scenario is having an instantiated K2 workflow process that relies on some data, but data is missing due to an SQL exception after the K2 process is started.  Transactions avoid these types of unwanted scenarios and ensure the overall integrity of the K2 system is maintained.
The code below demonstrates how both SQL and K2 participates in an atomic transaction.

1. using (TransactionScope ts = new TransactionScope())
{
2. db.SubmitChanges();
3. NewObject.ProcInstId = Workflow.StartSuggestionProcess(NewObject.Id);
4. db.SubmitChanges();
5. ts.Complete();
}

The code starts by defining a transaction scope (1) for the individual database (2, 4) and K2 operations (3).  The StartSuggestionProcess operation is a helper method in the Workflow static class.  It implements the SourceCode.Workflow.Client.Connection.StartProcessinstance method that creates a new instance of the K2 workflow process. If this process fails, the transaction won’t commit (5) and database changes won’t be applied.

An exception handler can be wrapped around the code to ensure the user is made aware of the failure and serials of the exception.

Transactions are important because they protect the overall integrity of a  system.  System.Transaction.TransactionScope is used to ensure that interdependent operations on the system (K2 and SQL in this example) are either all completed successfully or all cancelled successfully.

Need further technical advice or support?