Hello,
I am having a problem with serial numbers and worklist items.
I am saving the K2.SerialNumber in a process instance data field before a client activity which produces a worklist item (using a Default Client Event which has one action of 'processed'), I then clear the data field after the action has been performed.
I am trying to automate actioning these tasks in code outside of the workflow and when I try to open the worklist items for the saved serial number I get an error saying that the worklist item could not be found.
I am assigning the client event to a role and am (in code) impersonating the first user found in the role before opening the worklist item.
Does anyone know why the serial number isn't being stored correctly when it is being stored directly before the client event? There are a number of tasks, and each have their own data field - the action for any of them is 'processed'.
The code I'm using is below - and the 'pid' field is the saved serial number.
Private
Sub processTask(ByVal pid As String
)
Using servCon As Connection = New
Connection()
servCon.Open(SMServerConnString +
":5252"
)
If Not String.IsNullOrEmpty(pid)
Then
Dim master As SourceCode.Workflow.Client.WorklistItem = servCon.OpenWorklistItem(pid, "ASP", False
)
'RElease the item if it isn't available
If master.Status.ToString.ToLower() <> "available" Or master.Status.ToString.ToLower() = String.Empty
Then
master.Release()
End
If
'get the name of the user who this is assigned to
Dim targettedUser As String
= master.DelegatedUsers(0).Name
'check if the item is assigned to a role rather than a user
Dim umCB As SCConnectionStringBuilder = New
SCConnectionStringBuilder()
umCB.Host = SMServerConnString
umCB.Port = 5555
umCB.Integrated =
True
umCB.IsPrimaryLogin =
True
Dim um As UserRoleManager = New
UserRoleManager()
um.CreateConnection()
um.Connection.Open(umCB.ToString)
Dim targetIsRole As Boolean =
False
Try
If Not um.GetRole(targettedUser) Is Nothing
Then
targetIsRole =
True
End
If
Catch
targetIsRole =
False
End
Try
If targetIsRole
Then
'impersonate the first user in the role!
Dim role As
SourceCode.Security.UserRoleManager.Management.Role = um.GetRole(targettedUser)
If role.Include.Count > 0
Then
Dim roleUser As
RoleItem = um.GetRole(targettedUser).Include(0)
servCon.ImpersonateUser(roleUser.Name.ToString)
End
If
Else
'impersonate the assigned user
servCon.ImpersonateUser(targettedUser)
End
If
master =
Nothing
Dim oWLi As
SourceCode.Workflow.Client.WorklistItem = servCon.OpenWorklistItem(pid)
'set the task to processed to close it
oWLi.Actions(
"Processed"
).Execute()
'change the user back to the real one
servCon.RevertUser()
End
If
End
Using
End
Sub
Thanks,
Helen