This is the fourth of a multi part series on Nav 2016 events and workflows. This post will be a introduction to Workflows and how to make a workflow step.
First part : What are events and the advantages they provide.
Third Part: Creating event subscribers
Fourth Part : What are workflows and how to make a workflow step
Fifth part: Making a workflow response
Seventh Part: Assigning workflow step predecessors
Eighth Part: Putting it all together
Workflows are a way that allows the user to change process within Dynamics Nav without doing any coding or development work. A workflow is a series of workflow steps. A workflow step has three parts. First, what triggers the step. This could be the posting of a document, or a new record is created. Second is the condition, this is so only certain records are effected. Or it can be used to see if a condition is met before the third part happens. Which brings us to the last part, responses. Responses are what gets carried out once a step activates and passed the condition. This could be creating other records or setting certain fields.
The power with workflows is the ability to change any of these components without development. You can add/change/remove conditions, You can add, or remove responses. You can even insert and change the order of the steps. The only time development is required. Is when the step or response does not exist. Although, development on workflows have very little coupling. As long as you are either adding new steps or response. Merging your new changes with an existing system becomes very easy. Since you are not changing existing code. So lets look at how we can create a workflow step. We will have a look at responses in a later post.
One Step At a Time
There are two parts to making a workflow step. First we need to add it to the library of steps. Second we need to add the code for when we want the step to happen. Both of these parts only require one line of code.
To add our steps to the library its best to setup a function that subscribes to the “OnAddWorkflowEventsToLibrary” event from the “Workflow Event Handling” codeunit. This event will fire whenever the workflow page is opened, which will guarantee that our steps will be in the library when ever we go to add or change workflows. In the new function you just created add the in a “Workflow Event Handling” codeunit variable. The only line of code we need is the following.
WorkflowEventHandling.AddEventToLibrary(‘CREATECUSTOMEREVENTCODE’. DATABASE::Customer, ‘A new customer is created.’, 0, FALSE);
This will add a new step to the Library, the step ID will be ‘CREATECUSTOMEREVENTCODE’. It will use the customer table, and has a description of ‘A new customer is created.’. To active this step we only need to call one line of code. A common place to but this is usually at the end of a function that just did your step action, Ex: Post a document. Or in a seperate event subscribber. Ex: Subscribe to the OnAfterInsert from the customer table. The only variable you need is a “Workflow Management” codeunit. The only line of code is the following:
Here we need the same step ID as when we made the step, and we also need to pass in the record we are working with. Once this line of code is reached our step takes place.
To setup our workflow we need to navigate to the workflows page (Administration/Application Setup/Workflows). By simply navigating to this page we added our workflow step to the library. Lets create a new workflow. Put in a Code, a simple description and select a category if you like. Now if you select the drop down on the first record under “When Event” you should see list of workflow steps you can chose from. Yours should be on that list. Select your step. And if you want you can enter a conditon. By default the condtion is always true. So every time your “HandleEvent” line is reached the list of responses will happen. Speaking of responses you can add one or more if you want to for your workflow. If you are just looking to test out/ debug your new workflow there is a “Show Message” Response. This message will appear when ever this workflow step is activated.
Next we will look at making custom responses for our workflow steps. – 03/23/2016