Turning an Event into a Workflow Step

mark-995567_1920

With Dynamics Nav 2016 you now have the ability to setup workflows. These workflows let you change functionality of the system without changing any code. Most workflows can work off of a page action, field change or NAS job. But you can set them up to work off of an event firing as well. This way you will not miss a section of code where you need to fire off your workflow. Whenever the event happens, the workflow step happens.

The event we are going to use is an existing event, ‘OnAfterInsertEvent” on the customer table. This way, we can fire off our workflow when a customer is normally created through the card, or any other way in Nav. We want to do it OnAfter instead of OnBefore. We do this because the customer record would not be created yet if we used OnBefore. If we did try to access that customer record, we would get an error and actually crash Nav. Not good. To setup our workflow we need to make two functions, one to run when ever Nav decides to load all the workflow events, and the other as a subscriber for when the event actually fires.

Creating the Workflow Step

The first function requires a ‘Workflow event Handling’ codeunit variable.  The second requires a ‘Workflow Management’ codeunit variable. The next time you run Nav you should now see this workflow step when you create a new workflow.

The first function is subscibed to the “OnAddWorkflowEventsToLibrary” event int he “Workflow Event Handling” codeunit. The second is subscribed to “OnAfterInsertEvent” on the customer table.

‘CREATECUSTOMER’ in both these functions must match as this is like a key that gets passed around so Nav knows what workflow is currently going on.

Workflows

Working with events as workflow steps are really easy and let you have a lot of control over your system. You wont miss times when records are updated/created/deleted if you go off of the table triggers. You can use your own events as well, but for this scenario I just wanted to create the workflow step and not have to worry about making our own events. If you are looking for more info on 2016 workflows and events, here is a MSDN tutorial you can go through.

Leave a Comment