Welcome to K2 Underground Sign In | Join | Help
How to delegate/undelegate a worklistitem via API

K2 blackpearl provides the ability to delegate a task to another user.  This differs from a Redirect.  A Redirect will reassign a task that was assigned to me to another user.  A Delegate will permit someone else, in addition to myself, to action my task.  This is built into out of box K2 worklists, but if you need to build this into your own application it can be implemented via the SourceCode.Workflow.Management API. 

Below is some code providing some guidance on how it can be done:

        private void AddOrDeleteUserFromWorklistItem(int nProcInstID, 
                        int nActID, 
                        int nActInstID, 
                        int nActDestID, 
                        int nEventID, 
                        string strUserName, // must include the appropriate security label ('K2:' or 'K2SQL:')
                        bool bAddUser) // TRUE = add the user rights for this task; FALSE = delete the user rights this task
        {  
            // connect to K2 Management.  K2 server admin permistions are required.
           // this sample assumes the current user has such permissions.  if not, force the connection
           // via a connection string, to the appropriate user
            WorkflowManagementServer oK2Conn = new WorkflowManagementServer("localhost", 5555);
            oK2Conn.Open();

            // create an Actioner object for this user
            Actioner oActioner = new Actioner();
            oActioner.ActionerType = ActionerType.User;
            oActioner.Name = strUserName;

            // locate the currently assigned rights for this worklist item
            ActionInstanceRights arRights = oK2Conn.GetActionInstanceRights(nProcInstID,
                                                                                nActID,
                                                                                nActInstID,
                                                                                nActDestID,
                                                                                nEventID);

            // check to see if this user already exists for this task
            ActionInstanceRight oExistingRight = null;
            foreach (ActionInstanceRight oRight in arRights)
            {
                if (oRight.Actioner.Name.ToUpper() == strUserName.ToUpper())
                {
                    oExistingRight = oRight;
                    break;
                }
            }

            // now attempt to add or delete user rights for this task

            if (bAddUser)
            {
                // create a new user for this task if one doesn't alreday exist
                if (oExistingRight == null)
                {
                    ActionInstanceRight oActInstRight = new ActionInstanceRight();
                    oActInstRight.ProcInstID = nProcInstID;
                    oActInstRight.ActID = nActID;
                    oActInstRight.ActInstID = nActInstID;
                    oActInstRight.ActInstDestID = nActDestID;
                    oActInstRight.EventID = nEventID;
                    oActInstRight.Actioner = oActioner;
                    oK2Conn.CreateActionInstanceRight(oActInstRight);
                }
            }
            else
            {
                // delete a user for this task if it already exists
                if (oExistingRight != null)
                {
                    ActionInstanceRights arTmpActInstRights = new ActionInstanceRights();
                    arTmpActInstRights.Add(oExistingRight);
                    oK2Conn.DeleteActionInstanceRights(arTmpActInstRights);
                }
            }
        }

 

 

 

Published Thursday, July 24, 2008 4:30 AM by Bob

Comments

No Comments

Anonymous comments are disabled
Powered by Community Server (Commercial Edition), by Telligent Systems