Skip to main content

Hi all, 


 


I’ve a scenario wherein I need to delegate a task from one user to another using K2 blackpearl?


I should not do it from K2 workspace instead I should be doing this using K2 APIs.


Will the delegated task be available to the initial user as well?


Kindly let me know if anyone has worked on this before?


 


I've found the following URL on the K2 Underground site,


http://www.k2underground.com/blogs/fromthebench/archive/2008/07/24/how-to-delegate-undelegate-a-worklistitem-via-api.aspx


but I'm not sure from where can I fetch all the following Ids i.e.,


 


ProcessInstanceID


ActivityID


ActivityInstanceID


ActivityDestinationID


EventID


 


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)


{


 


}


 


If in case I want to delete the initial user as well what can be done?


How can I achieve this?


Kindly give your valuable inputs?


 


 


Thanks & regards,


Phanibabu Kandala

Dear 

 

Hope you're doing well 

 

it's me Darwish working on the same task at Pfizier Egypt 

 

did you reach any solution for it ?

 

Keep me posted if there any updates 


Hi,

 

Above code snippet i was written for setting out of office requirement through K2 API's which internally delegate task to delegatedUser. The same code you can still use to setup delegation via code. Just make sure you dont need to set OOF flag to true and rest everything remains same;

 

==============================================================================================================================================================================================================================

 

public static bool SaveOutOfOfficeStatus(string _sharredUser, string _delegateduser, int _outOfOfficeStatus, DateTime _startDate, DateTime _endDate)
{
bool success = false;
string sharer = ConfigurationManager.AppSettingsn"K2SecurityLabel"].ToString() + ":" + ConfigurationManager.AppSettingsn"WindowDomain"].ToString() + "" + _sharredUser;
string DelegateUser = ConfigurationManager.AppSettingsn"K2SecurityLabel"].ToString() + ":" + ConfigurationManager.AppSettingsn"WindowDomain"].ToString() + "" + _delegateduser;
Connection connection = new Connection();
connection.Open(GetK2BlackpearlConnectionString());
connection.ImpersonateUser(sharer);
int shareS = Convert.ToInt32(SourceCode.Workflow.Client.UserStatuses.OOF);

try
{

if (_outOfOfficeStatus == Convert.ToInt32(SourceCode.Workflow.Client.UserStatuses.None))
{
connection.SetUserStatus(SourceCode.Workflow.Client.UserStatuses.None);
}
else if (_outOfOfficeStatus == Convert.ToInt32(SourceCode.Workflow.Client.UserStatuses.Available))
{
connection.SetUserStatus(SourceCode.Workflow.Client.UserStatuses.Available);
}
else if (_outOfOfficeStatus == Convert.ToInt32(SourceCode.Workflow.Client.UserStatuses.OOF))
{
WorklistCriteria worklistcriteria = new WorklistCriteria();
worklistcriteria.Platform = "ASP";
// Send ALL Work based on the above Filter to the following User
Destinations worktypedestinations = new Destinations();
worktypedestinations.Add(new Destination(DelegateUser, DestinationType.User));
// Link the filters and destinations to the Work
WorkType worktype = new WorkType("MyWork", worklistcriteria, worktypedestinations);
WorklistShare worklistshare = new WorklistShare();
worklistshare.StartDate = _startDate;
worklistshare.EndDate = _endDate;
worklistshare.WorkTypes.Add(worktype);
connection.ShareWorkList(worklistshare);
connection.SetUserStatus(SourceCode.Workflow.Client.UserStatuses.OOF);  // comment this line which set OOF flag to true, if you dont need to set OOF
}

success = true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
// close the connection
if (connection != null)
{
connection.RevertUser();
connection.Close();
connection.Dispose();
}
}
return success;

}

==============================================================================================================================================================================================================================

 

If you find any issues let me know i can send you the broker for the same! but i would recommend you to try it before that!

 

 

Hope it helps!

 

Cheers,

Prajwal Shambhu


Reply