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