Setting a user's Out of Office Status

Setting a user's Out of Office status via the API may be required in custom automation code or in other custom code based solutions that interact with user worklists.

 These code snippets require references to the assemblies:

The following code sample demonstrates how to set a users Out of Office status:

using (SourceCode.Workflow.Client.Connection K2Conn = new Connection()) {
 //open a simple connection for simplicity
 K2Conn.Open("localhost");
 //set Out of Office ON for the current user
 K2Conn.SetUserStatus(UserStatuses.OOF);
 //set Out of Office OFF for the current user
 K2Conn.SetUserStatus(UserStatuses.Available);

 //set Out of Office ON for a managed user
 K2Conn.SetUserStatus(@"[Label]:[Domain\Username]", UserStatuses.OOF); //e.g. K2:DOMAIN\Username
 //set Out of Office OFF for a managed user
 K2Conn.SetUserStatus(@"[Label]:[Domain\Username]", UserStatuses.Available); //e.g. K2:DOMAIN\Username
}

The following code sample demonstrates how to define Out of Office worklist settings to specify how Worklist items should be delegated when the user is Out Of Office.

using (SourceCode.Workflow.Client.Connection K2Conn = new Connection()) {
 //open a simple connection for simplicity
 K2Conn.Open("localhost");

 //Define Worklist criteria to retrieve worklistitems to be delegated to the other user
 WorklistCriteria worklistcriteria = new WorklistCriteria();
 worklistcriteria.Platform = "ASP";
 //Define the user that the work must be delegated to as a Destination
 Destinations worktypedestinations = new Destinations();
 worktypedestinations.Add(new Destination(@"[Label]:[Domain\Username]", DestinationType.User)); //e.g. K2:DOMAIN\Username
 //Link the filters and destinations to the Work
 WorkType worktype = new WorkType("MyWork", worklistcriteria, worktypedestinations);

 //optional: define a separate set of criteria for any "Exception" tasks that
 //must be delegated to a different user, in this sample, tasks for a specific workflow
 WorklistCriteria worklistexceptioncriteria = new WorklistCriteria();
 worklistexceptioncriteria.Platform = "ASP";
 worklistexceptioncriteria.AddFilterField(WCField.ProcessName, WCCompare.Equal, "[ExceptionProcessName]");
 //Define the user that the exception work must be delegated to as a Destination
 Destinations worktypeexceptiondestinations = new Destinations();
 worktypedestinations.Add(new Destination(@"[Label]:[DOMAIN\ExceptionUserName]", DestinationType.User));
 // Link the filters and destinations to the Exception Work
 WorkTypeException worktypeexception = new WorkTypeException("MyWorkException", worklistexceptioncriteria, worktypeexceptiondestinations);
 worktype.WorkTypeExceptions.Add(worktypeexception);

 //now set up the worklist Out of Office (OOF) delegation
 WorklistShare worklistshare = new WorklistShare();
 worklistshare.ShareType = ShareType.OOF;

 //Set time interval for the Sharing. These dates may be used to only share work for a specific period
 worklistshare.StartDate = DateTime.MinValue;
 worklistshare.EndDate = DateTime.MinValue;

 //add the worktype
 worklistshare.WorkTypes.Add(worktype);
 //Share the worklist
 K2Conn.ShareWorkList(worklistshare);
 //Share the worklist for a managed user
 K2Conn.ShareWorkList(@"[Label]:[Domain\Username]", worklistshare);

 //When the current user's status is set to OOF the worklist shares defined above will take effect
 K2Conn.SetUserStatus(UserStatuses.OOF);
}

StartDate and EndDate Properties

The StartDate and EndDate fields exposed in the API are not currently supported in all User Interfaces where Out of Office can be configured.

The Out of Office status check box in K2 Workspace will reflect the user's status, regardless of the OOF Start or End dates. Therefore if the Start and End dates have been programmatically set and the user's status has been set to OOF, the K2 Workspace check box will show a check mark before, during, and after the Start and End dates. The workflowManagementServer.SetUserStatus(@"K2:[domain\username]", UserStatusses.OOF); will need to be reset to workflowManagementServer.SetUserStatus(@"K2:[domain\username]", UserStatusses.ACTIVE); in order for the K2 Workspace OOF check box to become unchecked. Alternatively, uncheck the OOF check box in K2 Workspace once the End date has been reached.

K2 blackpearl Developers Reference4.7
Video Links Learn Support
No videos found for this article
K2 on YouTube
No Additional links found for this article
No self-learning content for this article
Try some scenarios...
No relevant support links available for this article