Unchaining Workflows with Framework Part 1


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

  1. 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.
  2. Externalize process data,
    1. 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.
    2. Process data, key data for the process type is externalized allowing the data to be changed without redeployment of the workflow
  3. 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
  4. 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

  1. Process Management
    1. Externalized Data fields
    2. Configuration data
    3. Time slots
  2. Swagger Definition Library
  3. Script Library
  4. 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 String
K2FID String
ProcessTypeId String


  1. DataFieldId, will old the external data field Key
  2. K2FID, will hold the key value for the registered process istance
  3. 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.

Create References

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

Reference Name SmartObject Method Parameter
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.


Setup Activity

Every workflow that uses the framework must have an activity called ‘Setup’ This activity has a number of different things to do.

  1. It needs to register the instance of its self, to help keep a track of the instance
  2. Create the data field key, so we can use external data fields
  3. 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
Source K2F.SMO.ProcType GetTypeByProcessName Process Name ProcessTypeId
Destination DataField: ProcessTypeId

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
Source K2F.SMO.DataFields Create Key DataFieldKey
Destination DataField: DataFieldId

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’

Reference Name  
Source Free Text
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’

SmartObject Method Parameters Return
K2C.SMO.ProcInst Register Process Instance
Name Type Value Notes
pParentProcessId Number 0 or process instance Id of a parent process Default is 0 unless this workflow is being called via IPC or case Action then the parent process instance Id is required
pProcessInstanceId Number ProcessId [Context Browser].[Workflow Context Browser].[Process Instance]
pStatus Text Active
pViewFlow Memo View Flow [Context Browser].[Workflow Context Browser].[Process Instance]
pStartDate Date ProcessStartDate [Context Browser].[Workflow Context Browser].[Process Instance]
pBusinessKey Text 0 unless primary key of the main business data is known
pProcessTypeId GUID ProcessTypeId DataField
pProcessId Number 0
PFolio Text ProcessFolio [Context Browser].[Workflow Context Browser].[Process Instance]
pOriginator Text ProcessOriginatorFQN [Context Browser].[Workflow Context Browser].[Process Instance]
pDataFieldKey GUID DataFieldId Data Field
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’

SmartObject Method Parameters
K2F.SMO.Audit Add Audit
Name Type Value Notes
pDetails Text Starting [Name of workflow] Free text. what ever is appropriate
pProConfigId Number 0
pProcessInstanceId Number ProcessId [Context Browser].[Workflow Context Browser].[Process Instance]
pCreatedDate Date ProcessStartDate [Context Browser].[Workflow Context Browser].[Process Instance]
pCreatedBy Text ProcessOriginatorFQN [Context Browser].[Workflow Context Browser].[Process Instance]

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

  1.  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

  1. Drag a ‘Default Client Event’ on to the canvas or into an Activity
  2. Give your event a name
  3. Check ‘Task Item URL’
  4. Add the following SmartObject Method



SmartObject Method Parameters Return
K2F.SMO.Client ClientEventURL
Name Type Value Notes
pClientEventName Text ActivityInstanceName [Context Browser].[Workflow Context Browser].[Activity Instance]
pProcessTypeId GUID ProcessTypeId




  1. Make a note of the name the Activity is called where you have put the client event.
  2. 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

  1. Create a SmartObject Event
  2. Select ‘K2F.SMO.ProcInst’ SmartObject
  3. Select the ‘Update Status’ method
  4. For the input mapping ‘pStatus’ enter in free text to what the status is
  5. 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

  1. Click onclock  on the Acitivity
  2. Click ‘Next’, give the escalation a name
  3. Select a ‘Rule Template’, in this case i am going to select ‘Escalate After’
  4. Click ‘Next’
  5. Click on eclipse  in ‘Days’ to bring up the context browser.
  6. Add the following SmartObject Method



SmartObject Method Parameters Return
K2C.CMN.SMO.Time Read
Name Type Value
pTimeId GUID
References Value Filter
Configuration Data ProcessConfigValue ProcessConfigName = TaskTime

It doesn’t have to be ‘TaskTime’ it could be what ever you have called reference






  1. 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.
  2. Make a note of the name you passed into the ProcessConfigName. for example ‘TaskTime’
  3. You can also do the same for a ‘Start Rule’


End Activity

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

  1. Create a SmartObject’ event
  2. Select ‘K2F.SMO.DataField’ SmartObject
  3. Select the method ‘Delete Data Fields’
  4. It will ask for the ‘pDataFieldKey’ so assign it ‘DatafieldId’ Data field
  5. 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.


Audit Trail

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

  1. Drag  a SmartObject event onto the canvas
  2. Call the event ‘Create DataField’ or something similar
  3. Find  K2F.SMO.DataField SmartObject from the context browser
  4. Select the ‘Create Data Field’ method
  5. Now we need to supply the method with some additional information
    1. pDataFieldDescription, description of the data field we are creating
    2. pDataFieldKey, this is data field Key that we created earlier
    3. pDataFieldTitle, the name we are giving the data field
    4. pDataFieldValue, the value of the data field
    5. pProcessInstanceId, the id of the process instance
  6. Click ‘Next’ and ‘Finish’
  7. We have now created a external data field
  8. 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.


  1. Open the context browser
  2. Go to the data tab (3rd tab)
  3. Expand references
  4. Expand ‘External Datafields’
  5. Drag ‘DataFieldValue’ into the section you want to get the data field value
  6. The filter window opens up, click on ‘Add’
  7. In ‘Left’ select ‘DataFieldTitle’ from the drop down list
  8. Operation should be ‘=’
  9. 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


Line Rules

We can also use framework for line rules and other workflow logic

  1. Right click on a line
  2. Give the line appropriate name and prefix the name with ‘ln’. For example ‘lnVotingAge’
  3. In the label name section prefix it with ‘LR’ and then put what the rule is doing.
  4. Click on linerule  and click on ‘Add’
  5. Click on eclipse
  6. Expand ‘References’
  7. Expand ‘Configuration Data’
  8. Drag ‘ProcessConfigValue’ into the  ‘Variable’ section
  9. In Filter click on ‘Add’
  10. Select ‘ProcessConfigName’
  11. Select ‘=’ operation
  12. In Right, enter in the keyword for the value. for example ‘AgeLimit’
  13. Click ‘Next’ and ‘Next’ again
  14. Click ‘Finish’
  15. 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


  1. Goto form K2F.ADM.SMF.ProcessManager
  2. Click on ‘Add’ on the Form Library
  3. Enter in the name of the form
  4. Complete URL of the form
  5. Tick the checkbox
  6. Click ‘Save’
  7. 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.

  1. Click on ‘Client Event’
  2. Search for the desired form in the form library
  3. Give the ‘Client event name’ the same as  the activity the client event is in the workflow.
  4. Click on Save
  5. 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.

  1. 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
  2. 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

  1. Click on ‘Add Swagger Definition’
  2. Form loads up where you can enter in the definition name, host address and the definition it self
  3. demoswagger
  4. Click on ‘Submit’
  5. 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


Script Library

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

  1. Add
  2. Edit


when you have finished adding and editing scripts click on ‘Save’



Registering a process


  1. Deploy Process (This can be done at anytime during the workflow setup, but must be done before we carry on with the following steps)
  2. Goto form K2F.ADM.SMF.ProcessManager
  3. Click on ‘Register Process Type’
  4. A pop up window will appear enter in the workflow name, a description and a display name
  5. Click on submit, we have now told K2F about this workflow.
  6. 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.


  1. Click on ‘Add Time’
  2. Time configuration window opens
  3. Enter in a name, description
  4. Select a value from the drop down list for each of the time sections
  5. Click on Submit
  6. 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

Configuration data is used to hold information that will be needed for every instance of a particular workflow.


  1. Click on ‘Add’
  2. Enter in a description of config data being added
  3. Enter in the actual value
  4. Enter in a name for the config data
  5. 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.









Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s