HI,
For the ShareWorklist method, if you use the overload with 2 input, the first parameter is "ManagedUserName". Not very sure what this is for, but the "Managed" wording usually means the manager account. So, you code should be using the overload with the WorklistShare input only.
I tested this code to be working fine in impersonating and setting OOF:
public void SetMyOOFStatus(bool OOF)
{
Console.WriteLine("Executing SetMyOOFStatus");
SCWFC.Connection wfConn = new SCWFC.Connection();
try
{
wfConn.Open(SERVER_NAME);
wfConn.ImpersonateUser("K2:K2Trainhrmgr1");
if (OOF)
{
//Create a share
SCWFC.WorklistShare wlShare = new SCWFC.WorklistShare();
wlShare.ShareType = SCWFC.ShareType.OOF;
wlShare.StartDate = DateTime.Now;
wlShare.EndDate = DateTime.Now.AddDays(1);
//Forward destination
SCWFC.WorkType wtShare = new SCWFC.WorkType("normal");
wtShare.WorklistCriteria.Platform = "ASP";
wtShare.Destinations.Add(new SCWFC.Destination(@"K2:k2trainhradmin1", SCWFC.DestinationType.User));
//Exception destination
//SCWFC.WorkTypeException wtExp = new SCWFC.WorkTypeException("except");
//wtExp.WorklistCriteria.Platform = "ASP";
//wtExp.WorklistCriteria.AddFilterField(SCWFC.WCField.ProcessName, SCWFC.WCCompare.Equal, "ExpenseReview");
//wtExp.Destinations.Add(new SCWFC.Destination(@"K2:K2Trainizmgr1", SCWFC.DestinationType.User));
//wtShare.WorkTypeExceptions.Add(wtExp);
//add to worklistshare
wlShare.WorkTypes.Add(wtShare);
//remove all existing share
wfConn.UnShareAll();
//add WorklistShare
wfConn.ShareWorkList(wlShare);
//set user to be OOF
wfConn.SetUserStatus(SCWFC.UserStatuses.OOF);
}
else
{
wfConn.UnShareAll();
wfConn.SetUserStatus(SCWFC.UserStatuses.Available);
}
}
finally
{
wfConn.Dispose();
}
}
Good luck
JK