K2 process data access

  • 27 September 2005
  • 18 replies
  • 25 views

Badge +2
Hello!

We're building a solution in which we need to export K2 process data into XML format (I mean all the process/activity fields with type and content).
Is there any 'tool' to do this as process admin (or code snippet to do programmatically)?

It would be useful to 'backup' all the process data either inside from a running process automatically (user code) or from outside when process is completed.

Could you give me some hints about solving this problem? Is it suggested to store all the fields in an XML field to do this? I'm courius of the other side, too (filling in data to another process like IPC, and start that process).

Please give some detailed info (w/ code and explanation). Thank you for helping in advance.

Regards,
Peter

18 replies

Badge +11
Hi Peter,

I suppose you do know about the 'Export Process XML' item on the Tools menu of K2.net Studio. This function will export your process definition to an xml file but if I understand you correctly, you're looking for a tool to export completed process instances from the K2Log database to an xml file. Not sure why you would want to do this for backup purposes since it already exists in a database which should be backed up on a regular basis. Reporting purposes I suppose would make more sense to me. Unfortunately, there does not exist any out-of-the-box utility to achieve this.

I also unfortunately do not know of any other client who has previously done this. If nobody else answers this posting, I'm afraid you'll have to do a bit of custom coding.

Please contact your local K2Workflow support office and request the K2Log database ERD which should help you understand the layout of the database better.

Sorry I couldn't be of more help,
Ockert
Badge +2
Hi Ockert!

First, thank you for information about ERD, I'll write a mail to SourceCode.

The solution we'd like to solve is to be able to export process DATA (fields with type and current content in XML) on running processes. We'd like to achieve this in order to be able to "re-run" a process with the "new" version.
I write down an example to clearly understand this situation. We've a process called Process 1. It has 100 running instances. We'd like to modify this process and add another "approval" activity in the flow. We do this, recompile, and all the newly started instances will start as this version 2 with one more approval. But, we'd like to export data of all that 100 old-version running instances, and we'd like to start 100 new-version instances with the exported data in the name of the original Originator user.
I'd like to know if this is possible and when it is, how can it be done?

Main questions are:
1) How to easily export ALL (current state) process data into Xml from 'outside' of the process as an Administrator? I mean connect to the running process instance and export all the data.
2) How to start a process in the name of a User while having Administrator credentials? I mean when I'm Administrator and I'd like to start Process 1 in the name of John who needs to be Process 1's Originator?

Hope you can help:)

Thanks in advance.

Peter
Badge +11
Anything is possible. The question is how much time you will have to spend creating a custom solution since such a utility does not exist.

To answer your questions:

How to easily export ALL (current state) process data into Xml from 'outside' of the process as an Administrator? I mean connect to the running process instance and export all the data.

There's no easy way. It will entail running custom queries against the K2Log database to extract the necessary information and create an xml file. Data types are not stored in the K2Log database and you will not be able to extract it from the K2 transaction database. I would suggest you export the process definition from K2.net Studio to an xml file. Save it with an appropriate name to reflect process name and version exported. This file will give you some indication of datatypes etc. You can then combine this file with the information extracted from the K2Log Database for the Process Instances which are not yet complete and running on the specific version of process definition.

How to start a process in the name of a User while having Administrator credentials? I mean when I'm Administrator and I'd like to start Process 1 in the name of John who needs to be Process 1's Originator?

You'll have to use the K2ROM object model to Create a new process instance, populate datafields and Start the new process instance. Please refer to the help file for sample code. The connection object will allow you to connect to the K2.net Server with the credentials of another user. You will obviously need the user's password. Now, apart from creating a new process instance running on the new version of the process definition, you will also need to delete the process instance running on the old version. For this you will need to reference the K2Mng object model. Sample code also available in the help file.

Hope this makes sense,
Ockert
Badge +2
Hi Ockert,

This is exactly what I needed. In the meanwhile, I developed an asp.net page on which user could enter the process instance id, and when the submit button is pushed, the following things happen:
1) establish k2 connection
2) open old process instance by id
3) create new process instance
4) copy DataFields[] and XmlFields[] from old into new instance
5) start new process instance
6) close connection

Remaining tasks currently finding information about:
1) stop (terminate, delete?) old process instance
2) get old process instance current activity
3) set new process instance current activity (GotoActivity?)

Some questions (for Reporting "version changed" processes correctly):
1) how to set the old instance's "history" to the new one
2) how could I "connect" old instance to new

When ready, I may post my code. I think others are interested as well. If you've some hints, corrections, answers, on questions I asked, please don't hesitate to write:) I'd be pleased.

Thank you for helping:)

Peter
Badge +11
Sounds good - you're on the right track...

Remaining tasks currently finding information about:
1) stop (terminate, delete?) old process instance - K2MNG
2) get old process instance current activity - Difficult, I'll have to think about this one.
3) set new process instance current activity (GotoActivity?) - K2MNG

Some questions (for Reporting "version changed" processes correctly):
1) how to set the old instance's "history" to the new one - for auditability, can and should not be done. New process will create its own history.
2) how could I "connect" old instance to new - Reporting? No way!! (At least that I know of)

Happy coding,
Ockert
Badge +2
goin' on:)

remaining where suggestion needed:
1) should I stop or delete process instance? which one do you suggest? when stopping, it's also disappear from task list, ain't? or delete is the solution?
2) I'm also finding how... :) how?:) this string should be needed on the new instance GotoActivity()

others:
I think because Originator will be lost when restarting processes because no password will be supplied, an Originator data field will be used to cover this. But because of this, I may create a copy named "Process 1/restarted" version of the process, with modified Originator handling. In this case, in reports it's much more separatable which processes were restarted and which are not. I think that will be enough.

Thanks for answers and waiting for others:) Thank you:)

Peter
Badge +11
When you stop a process instance, it will always stay 'alive' in the K2 transaction database - until you start it again and complete the rest of the process. Deleting the process instance from the K2 transaction database is one option as long as you don't delete it from the K2Log database as well. Personally, I don't like deleting process instances. I would have an Activity with an 'empty' Default Server Event at the end of each process to which I will implement a 'GotoActivity'. In this way the process will be completed gracefully and moved to the K2Log database.

Not sure what you're asking in the second question.

What happens if a process splits into parallel Activities? You'll need some way of obtaining the Activity statuses for each running process instance - similar to what can be seen in Reporting in K2.net Workspace. Not sure if you can send a process to more than one Activity with 'GotoActivity'.

Your Originator concept sounds fine but will definitely complicate your process design a bit.

Regards,
Ockert
Badge +2
1) OK, I think I'll use your 'empty last step' method.

2) As in my previous post. How to get 'current' activity name of a process instance?

In more complicated situations where parallel processing is applied, I think I'll just restart process with the old instance data and step ahead until the point where the old and new versions are the same.

Thank you, and if you know, please tell me how to get current activity name.

Have a nice rest, c u tomorrow
Peter
Badge +11
I think you can do it in 2 ways...

1. Design your process in such a way to keep track of where each process instance are i.e. write to a separate database the process instance id and activity name of each step. When you then need to 'kill' the old process instance, you can refer to this table to find out exactly where it was previously.

2. Run a query on the K2Log Database extracting ONLY the ACTIVE (running) Activity instances for a specific process instance id - Have a look at K2.net Workspace Reporting for Activity Instance Statuses.

Regards,
Ockert
Badge +2
Hi Ockert,

I chose the second solution in which I fetch current activity from database.

Following query can be used to fetch all active process instances for a specified process (ProcSet) and a specified version (Ver). Getting current activity for process is also included. Runs on K2 database.


SELECT
_ProcInst.ID AS ProcessInstanceID,
_ProcSet.FullName AS ProcessName,
_Act.Name AS CurrentActivityName
FROM
_Proc (NOLOCK)
INNER JOIN
_ProcSet (NOLOCK)
ON
_ProcSet.ID = _Proc.ProcSetID
INNER JOIN
_ProcInst (NOLOCK)
ON
_ProcInst.ProcID = _Proc.ID
INNER JOIN
_WorkListHeader (NOLOCK)
ON
_WorkListHeader.ProcInstID = _ProcInst.ID
INNER JOIN
_Act (NOLOCK)
ON
_Act.ID = ActID
WHERE
_ProcInst.Status <> 4 AND
_Proc.Ver = 3 AND
ProcSetID = 19


Only one more question is there, what data should be copied from old version to new in order to make sure that everything is copied?
Currently I copy DataFields[] and XmlFields[]. What else should be? Maybe activity fields? How?

Thanks is advance.

And many thanx for real helping,
Peter
Badge +11
Hi,

I'm impressed!!

I hope "Runs on K2 database" it is a typo. Running queries on the K2 transaction database can negatively influence the performance of the K2.net system and is not permitted. Please try to restrict your queries to the K2Log database.

Process level data- and xml fields should be sufficient. I do not think it would be possible to transfer Activity level data- and xml fields because the Activities has not been instantiated by the time you plan the new process. Once you've planned the new process instance and redirected flow to the appropriate Activity with the 'GotoActivity' method, I suppose you can set that Activities process level variables - but what would be the point, you'll probably need input from the users at this point anyway.

Regards,
Ockert
Badge +2
Hi Ockert,

I made the 'K2Log' version of the previous query that can be used to fetch all active process instances for a specified process (ProcSet) and a specified version (Ver). Getting current activity for process is also included. Runs on K2Log database.


SELECT
_ProcInst.ID AS ProcessInstanceID,
_ProcSet.FullName AS ProcessName,
_Act.Name AS CurrentActivityName
FROM
_Proc (NOLOCK)
INNER JOIN
_ProcSet (NOLOCK)
ON
_ProcSet.ID = _Proc.ProcSetID
INNER JOIN
_ProcInst (NOLOCK)
ON
_ProcInst.ProcID = _Proc.ID
INNER JOIN
_ActInst (NOLOCK)
ON
_ActInst.ProcInstID = _ProcInst.ID
INNER JOIN
_Act (NOLOCK)
ON
_Act.ID = _ActInst.ActID
WHERE
_ProcInst.Status <> 4 AND
_ActInst.Status = 2 AND
_Proc.Ver = 3 AND
_Proc.ProcSetID = 19


This works fine. Thanks for your tips and help.

When finished, I may post the C# code of the copy-old-new code snippet with which 'restarting' is possible.

Good afternoon (think it is on your location, too),

Peter
Badge +9
Hi Reggy,

What you want to do now is create a custom report with you new query that makes use of the available APIs

Have a look at the following Knowledge Base article: http://kb.k2workflow.com/Articles/KB000021.aspx this is essentially what you are looking for.
Badge +2
Hi Rénier,

And thanks for the tip on reporting. I also bookmarked KB000021 to generate reports, but that will be a later task. But then, I'll read that article.

Thanks,
Peter
Badge +13
Can we expect FilterService web service to migrate towards BlackPearl?
I have a few new solutions that I'd like to make use of FilterService.
Badge +11
I haven't got the details, but I don't think so - my opinion only.

Regards,
Ockert
Badge +13

Is there an equivalent in functionality to K2 .NET 2003 FilterService from this new set of features?


http://k2underground.com/blogs/comingsoon/archive/2011/01/17/k2-web-services-part-1.aspx

Badge +1

Does anyone have and ERD for K2 and K2Log database? I could use some help understanding the data structure.


 


TIA.

Reply