Wednesday, May 13, 2009

K2 Blackpearl - Get Task List Item in Sharepoint Workflow Integration

Using K2 Blackpearl features like Sharepoint events can be very usefull and easy to develop a workflow in few minutes. Althought, sometimes there are pitfalls that frustrate your initial purpose. For example, one of this day, I run against Sharepoint Workflow Integration features. I create my simple approval process in figure but, initially, I can't to get the task item ID created during Sharepoint Workflow Integration Client [SWIC]. I needed this ID because in my final activity I set a Sharepoint List Items event to delete the Task List Item created during the previous activity (SWIC, see Delete Task Activity in the figure above). To accomplish to this necessity, I had to create a new process DataField which I called "TaskId" Then I had to go inside the code generated by SWIC event and I modified the ExecuteForUser method body in the follow manner:
string taskIDstring = service.ModifyWorkflowAndGetTaskID(listId, listItemId,

                          workflowInstanceId, modificationID, contextData, "");



// Put task item id into process data field "TaskID"

string taskID = taskIDstring.Split(new string[] { "?ID=" },

                        StringSplitOptions.None)[1];

K2.ProcessInstance.DataFields["TaskID"].Value = taskID;
"service.ModifyWorkflowAndGetTaskID" calls a K2 web service who return a string contain the url of the task. A string like this: http://your MOSS server/Lists/Tasks/DispForm.aspx?ID=3.
Thank to this code I'm been able to delete Task List Item at the end of my process:
kick it on DotNetKicks.com
Save to delicious 0 saves

No comments:

Post a Comment