Building workflows in K2 is great, we can drag and drop events onto the canvas , click through wizards that tell us what to do. We can setup line rules, tasks etc.. With just using a mouse. Which is fantastic as its quick and easy.
We can also deploy a workflow following a simple wizard too.
But when we want to change something in a email, or change the form that the task is pointing too etc.. It involves opening up the solution and making those changes and redeploying and then only new instances of that workflow picking up those changes.
So what do we do? Well we do what i tell all my clients, we make everything in the workflow that could dynamic. We store the url of a form in a data store somewhere and the same for email content or the business rules like escalation values. We basically unchain the workflow from the data. We free it so we can make these type of changes from outside the workflow. So we don’t have to go back into the workflow and make the change and then redeploy. We just go to a simple form and make the change and then any workflow which is pointing to this value will automatically receives the change. Sounds brilliant doesn’t it?
So over the years myself and my colleagues have been slowly putting a framework/ pattern together.
It doesn’t have a fancy name so throughout this article i am just going to call it framework.
The framework designed to make the workflows adaptable to change without having to redeploy the workflow each time. Its also designed to make building a workflow quicker and giving the people the involved from developers, administrators and users a complete overview of what is happening.
Some of the features of framework are
- Headless forms, with framework, we can make the task forms dynamic so at run time we can choose what form the task will be get.
- Externalize process data,
- External data fields are created outside of the workflow, allowing workflows to be more efficient and for the data data to be deleted after the instance has finished instead of persisting after the instance has finished.
- Process data, key data for the process type is externalized allowing the data to be changed without redeployment of the workflow
- Audit trail, every workflow has a audit trail allowing users to keep track of important changes within the flow of the instance of a workflow
- Workflow registration, every workflow is registered allowing users, developers and admin to keep track of what workflows are running , if they are related to another workflow and how complete an instance of a workflow type is.
Components of framework
- Process Management
- Externalized Data fields
- Configuration data
- Time slots
- Swagger Definition Library
- Script Library
- Form Library
To use the framework within your workflow, we need to setup a few things inside the workflow and also outside the workflow.
Setting up a workflow to use the framework
Create Key Data Fields
First thing we need to do is create the three main data fields that every workflow using the framework should have.
|Data field name||Type|
- DataFieldId, will old the external data field Key
- K2FID, will hold the key value for the registered process istance
- ProcessTypeId, holds the key for type of process
There will probably be fourth data field that is not mentioned above, which will be the primary key for the main business data.
To make life easier when it comes to designing \ developing workflows the framework recommends we use ‘References’ to create short cut to a SmartObject method and its properties of data.
To create a reference, go to the data tab (3rd) and right click on ‘References’ and follow the instructions.
The references that we need to create are as follows
|Configuration Data||K2F.SMO.ProCon||GetProcessConfig||ProcessTypeId (Data field)|
|External Datafields||K2F.SMO.Datafields||Get Datafields||DataFieldId (Data field)|
Configuration data, contains values for the process type
External Data fields will contain data for the instance of the process
Like the Data fields, you may also have a third one for your main business data.
Every workflow that uses the framework must have an activity called ‘Setup’ This activity has a number of different things to do.
- It needs to register the instance of its self, to help keep a track of the instance
- Create the data field key, so we can use external data fields
- Start auditing the key stages of the workflow
1.Within your workflow create an activity called ‘Setup’
Getting the Process Type Id
In the ‘Setup’ Activity, drag a ‘Data Event’ into the activity, give it the name ‘Get Process TypeId’
|Reference Name||SmartObject||Method||Parameter||Return Property|
Now we have the process type id, it will allow the workflow to get all related framework information relating to this workflow type.
Creating a Data Field Key
In the ‘Setup’ Activity drag the ‘Data Event’ into the activity and give it the name ‘Create DataField Key’
|Reference Name||SmartObject||Method||Return Property|
DataFieldId is what we will use to group the process instance data fields together.
Creating a Folio
In the ‘Setup’ Activity drag the ‘Data Event’ into the activity and give it the name ‘Set Folio’
|Destination||[Context Browser].[Workflow Context Browser].[Process Instance].Folio|
Registering the instance of a workflow
By registering the instance against the workflow type allows the framework to keep track of how many instances of a particular type is running and to make sure the correct details and other key values are being used.
Create a SmartObject event inside the ‘Setup’ activity and name it ‘Record Workflow’
|K2C.SMO.ProcInst||Register Process Instance||
|ID, assigned to K2CID datafield|
Creating a Audit entry
Now that the instance is registered, against the process type, we need to make an entry in the audit log so we can show what record that the instance has started. Create a SmartObject event inside the ‘Setup’ Activity and call it ‘Add to Audit’
The ‘Add to Audit’ event can be copied and pasted into other activities in the workflow and you just need to change pDetails, and pCreatedDate
- The ‘Setup’ Activity should now look like this
The workflow is now setup to use the framework
Client Events with the framework
With framework the form’s URL is dynamic and is stored externally, allowing the form to be changed at any point. With out the need to go back into the workflow
To do set this up in the workflow carry out the following steps
- Drag a ‘Default Client Event’ on to the canvas or into an Activity
- Give your event a name
- Check ‘Task Item URL’
- Add the following SmartObject Method
- Make a note of the name the Activity is called where you have put the client event.
- Goto orm url here’
Updating the framework of a workflow instance status
The framework likes to keep track of the status of the workflow that is registered. This allows us to do reporting and to offer additional functionality based on it’s status.
To update the framework of a status change follow these steps
- Create a SmartObject Event
- Select ‘K2F.SMO.ProcInst’ SmartObject
- Select the ‘Update Status’ method
- For the input mapping ‘pStatus’ enter in free text to what the status is
- For ‘pId’ input parameter use the data field ‘K2FID’
This event like the audit can be copied into other activities where the status needs to be updated.
Dynamic Escalation and Start Rules
When there needs to be an escalation on an ‘Activity’ or ‘Process’ we can use K2CF, to make the time frames dynamic.
Setting up the escalation
- Click on on the Acitivity
- Click ‘Next’, give the escalation a name
- Select a ‘Rule Template’, in this case i am going to select ‘Escalate After’
- Click ‘Next’
- Click on in ‘Days’ to bring up the context browser.
- Add the following SmartObject Method
- Repeat steps 5 and 6 for Hours, Minutes and Seconds, changing the return value for to the correct return property based on section. For example if you are on hours , then the return would be hours.
- Make a note of the name you passed into the ProcessConfigName. for example ‘TaskTime’
- You can also do the same for a ‘Start Rule’
Every workflow must have an ‘End’ Activity. In this activity we delete all external data fields relating to the instance of this workflow. We update the status of the process instance information and update the last entry in the audit table for the instance.
Deleting External Data Fields
- Create a SmartObject’ event
- Select ‘K2F.SMO.DataField’ SmartObject
- Select the method ‘Delete Data Fields’
- It will ask for the ‘pDataFieldKey’ so assign it ‘DatafieldId’ Data field
- Complete the event. Now when this event is executed it will delete all the datafields that were created for this instance. Making the workflow efficient in cleaning up data it no longer needs.
The end activity will also need an entry into the audit to say that it has finished
Updating the framework on process status
The framework process instance status will also need to be updated to ‘Complete’
Creating an external Data Field
To create an external data field
- Drag a SmartObject event onto the canvas
- Call the event ‘Create DataField’ or something similar
- Find K2F.SMO.DataField SmartObject from the context browser
- Select the ‘Create Data Field’ method
- Now we need to supply the method with some additional information
- pDataFieldDescription, description of the data field we are creating
- pDataFieldKey, this is data field Key that we created earlier
- pDataFieldTitle, the name we are giving the data field
- pDataFieldValue, the value of the data field
- pProcessInstanceId, the id of the process instance
- Click ‘Next’ and ‘Finish’
- We have now created a external data field
- Repeat steps 1 to 6 for additional external data fields if needed
Using an external data field
To use an external data field, in the event or the line rule you are in.
- Open the context browser
- Go to the data tab (3rd tab)
- Expand references
- Expand ‘External Datafields’
- Drag ‘DataFieldValue’ into the section you want to get the data field value
- The filter window opens up, click on ‘Add’
- In ‘Left’ select ‘DataFieldTitle’ from the drop down list
- Operation should be ‘=’
- In ‘Right’ enter the name of the data field you want to get the value of.
10. Click ‘Next’
11. Make Sure ‘DataFieldValue’ is selected and click ‘Next’
12. Make sure ‘Return a single item’ is checked and click ‘Finish’
13. We have now called the external data fields to get the value for a particular data field
We can also use framework for line rules and other workflow logic
- Right click on a line
- Give the line appropriate name and prefix the name with ‘ln’. For example ‘lnVotingAge’
- In the label name section prefix it with ‘LR’ and then put what the rule is doing.
- Click on and click on ‘Add’
- Click on
- Expand ‘References’
- Expand ‘Configuration Data’
- Drag ‘ProcessConfigValue’ into the ‘Variable’ section
- In Filter click on ‘Add’
- Select ‘ProcessConfigName’
- Select ‘=’ operation
- In Right, enter in the keyword for the value. for example ‘AgeLimit’
- Click ‘Next’ and ‘Next’ again
- Click ‘Finish’
- In the second variable put in your business data as normal.
We have now set up a dynamic line rule where both the business data the variable that its being compared against is coming from outside of the workflow
Managing the framework
Adding a form to the form library
All forms created either Smartforms or HTML 5 forms must be registered, to allow the framework to use the forms in the workflows
- Goto form K2F.ADM.SMF.ProcessManager
- Click on ‘Add’ on the Form Library
- Enter in the name of the form
- Complete URL of the form
- Tick the checkbox
- Click ‘Save’
- The form is now registered and can be used.
Adding A Form to A Task
For Default Client Events to get a form in a workflow, we need to link up the form and client event together.
- Click on ‘Client Event’
- Search for the desired form in the form library
- Give the ‘Client event name’ the same as the activity the client event is in the workflow.
- Click on Save
- We can use this form now in the workflow as described above
Swagger Definition Library
K2F provides support for managing the swagger definitions of the REST Broker. It will do this in two ways.
- There will be a Web API Handler that accepts Posts, the idea being that when the global registry changes it will post to the service with the new host address and application name. The service then goes into the library and finds the correct swagger definition and updates it with the new host address. It then exports the swagger definition file to the swagger folder on the server and then updates K2 with the new definition. ToDo
- In the portal you can view all the swagger definitions, where new ones can be added and old ones can be edited. Once created in the library, this will then create Swagger JSON file on the K2 Server.
Add a new Swagger file
- Click on ‘Add Swagger Definition’
- Form loads up where you can enter in the definition name, host address and the definition it self
- Click on ‘Submit’
- This will save the swagger definition in the library and also create its corresponding JSON file on to the server.
5.You will still need to create the instance manually using the service object tester tool
Some smartforms may require additional scripts to be used such as the K2C.CMN.VWI.Footer view. Like with the workflows instead of hard coding the script into the view and having to check out and check in the view every time there is change. The script library allows us to make the change from the management tool, without the risk of breaking the view or form.
From the script library the following actions are possible
when you have finished adding and editing scripts click on ‘Save’
Registering a process
- Deploy Process (This can be done at anytime during the workflow setup, but must be done before we carry on with the following steps)
- Goto form K2F.ADM.SMF.ProcessManager
- Click on ‘Register Process Type’
- A pop up window will appear enter in the workflow name, a description and a display name
- Click on submit, we have now told K2F about this workflow.
- We can now start to add in configutation data about the workflow.
Process Configuration Data
In the process configuration form, we can add,edit configuration data of a workflow.
Navigating to this form can be done either by clicking on the process type or by adding a new process type.
Adding Time Configuration
To add time configuration that will be used for Escalations and Start Rules as mentioned above.
- Click on ‘Add Time’
- Time configuration window opens
- Enter in a name, description
- Select a value from the drop down list for each of the time sections
- Click on Submit
- Time is now added
So that we use the time frame in a workflow , we now need to link the time frame to the ‘Configuration Data’
Configuration data is used to hold information that will be needed for every instance of a particular workflow.
- Click on ‘Add’
- Enter in a description of config data being added
- Enter in the actual value
- Enter in a name for the config data
- In this example we are going to add the link the to the time frame we created earlier.
As you can see the framework allows workflows to be flexible and allows for apps to be build apps fast and easily.
Now that the framework has been introduced , next time we will look at what else it can do and build a workflow using it.