This discussion is archived
7 Replies Latest reply: Dec 13, 2012 2:18 PM by 868989 RSS

Assign tasks automatically when vacation set for a user

868989 Newbie
Currently Being Moderated
Hi,
I've a requirement where user can set the vacation period and rules. When the vacation period starts, all the tasks already assigned to him should get REASSIGNED AUTOMATICALLY to the other user that we configured in the vacation rule. How can I achieve this? Please suggest me some ideas.

Thanks
  • 1. Re: Assign tasks automatically when vacation set for a user
    BillWallen Explorer
    Currently Being Moderated
    I assume you are using the Workspace...

    Vacation rules are enforced on a point-forward basis. Have the user finish their assigned work before going on vacation or reassign the tasks manually.

    You could write some logic to search for all these instances assigned to that particular user and reassign them to another user; however, I'm not sure there is a hook available in the Workspace from which to call this logic.
  • 2. Re: Assign tasks automatically when vacation set for a user
    user67225 Newbie
    Currently Being Moderated
    What version of BPM are you using?
  • 3. Re: Assign tasks automatically when vacation set for a user
    868989 Newbie
    Currently Being Moderated
    Thanks for your reply Bill. I am trying to execute my own logic to reassign the tasks manually.

    I am creating a new task flow where user enters the userId to which the task will be reassigned. When user clicks the 'Submit' button, calling the below code. Here I need to pass the userName and pwd of the logged in user to get the IWorkflowContext. Is there a way to avoid passing the pwd in the code. How can I get the IWorkFlowContext without passing userName/pwd.

    public void reassignTasks(ActionEvent actionEvent) {
    // Add event code here...
    try
    {
    //Create JAVA WorflowServiceClient
    IWorkflowServiceClient wfSvcClient = WorkflowServiceClientFactory.getWorkflowServiceClient(
    WorkflowServiceClientFactory.SOAP_CLIENT);

    ITaskQueryService querySvc = wfSvcClient.getTaskQueryService();
    ITaskService taskService = wfSvcClient.getTaskService();

    //Login as jstein
    IWorkflowContext ctx = querySvc.authenticate("user1","welcome1".toCharArray(),null);

    List queryColumns = new ArrayList();
    queryColumns.add("TASKID");
    queryColumns.add("TASKNUMBER");
    queryColumns.add("TITLE");
    queryColumns.add("OUTCOME");

    //Query a list of tasks assigned to jstein
    List tasks = querySvc.queryTasks(ctx,
    queryColumns,
    null, //Do not query additional info
    ITaskQueryService.AssignmentFilter.MY,
    null, //No keywords
    null, //No custom predicate
    null, //No special ordering
    0, //Do not page the query result
    0);
    //Get the task service
    ITaskService taskSvc = wfSvcClient.getTaskService();
    //Loop over the tasks, outputting task information, and approving any
    //tasks whose outcome has not been set...
    for(int i = 0 ; i < tasks.size() ; i ++)
    {
    Task task = (Task)tasks.get(i);
    int taskNumber = task.getSystemAttributes().getTaskNumber();
    String title = task.getTitle();
    String taskId = task.getSystemAttributes().getTaskId();
    String outcome = task.getSystemAttributes().getOutcome();
    List assignees = new ArrayList();
    assignees.add("anpeiris");
    taskSvc.reassignTask(ctx, taskId, assignees) ;
    System.out.println("============================== After reassigning the task ==================================");

    System.out.println("Task #"+taskNumber+" ("+title+") is "+outcome);
    }

    }
    catch (Exception e)
    {
    //Handle any exceptions raised here...
    System.out.println("Caught workflow exception: "+e.getMessage());
    }
    }

    Thank you.
  • 4. Re: Assign tasks automatically when vacation set for a user
    868989 Newbie
    Currently Being Moderated
    Thanks Pradeep. I am using 11.1.1.5 version.
  • 5. Re: Assign tasks automatically when vacation set for a user
    BillWallen Explorer
    Currently Being Moderated
    Instead of getting a handle on IWorkflowServiceClient, look at oracle.bpm.client.BPMServiceClientFactory. There is a service called IBPMUserAuthenticationService that has a getBPMContextForAuthenticatedUser() method. This will give you a BPMContext for the logged in user. Then, you should be able to do anything task access permits.
  • 6. Re: Assign tasks automatically when vacation set for a user
    868989 Newbie
    Currently Being Moderated
    Hi Bill,
    I am able to reassign/delegate the task to a SINGLE user programmatically using the below code.

    private void vacationTask(String taskAction) {
    String errorMessage = "Below users are not valid: ";
    boolean isFirstInvalidUser = true;
    FacesContext facesContext = FacesContext.getCurrentInstance();
    FacesMessage facesMessage = null;
    try {
    String contextStr = ADFWorklistBeanUtil.getWorklistContextId();
    IWorkflowServiceClient wfSvcClient = WorkflowService.getWorkflowServiceClient();
    ITaskQueryService querySvc = wfSvcClient.getTaskQueryService();
    ITaskService taskService = wfSvcClient.getTaskService();

    IWorkflowContext ctx = querySvc.getWorkflowContext(contextStr);
    String loggedInUser = ctx.getUser();

    List queryColumns = new ArrayList();
    queryColumns.add("TASKID");
    queryColumns.add("TASKNUMBER");
    queryColumns.add("TITLE");
    queryColumns.add("OUTCOME");

    List tasks = querySvc.queryTasks(ctx,queryColumns,null,ITaskQueryService.AssignmentFilter.MY,null,this.getTaskPredicate(),null,0,0);

    ITaskService taskSvc = wfSvcClient.getTaskService();



    for(int i = 0 ; i < tasks.size() ; i ++) {
    Task task = (Task)tasks.get(i);
    String title = task.getTitle();
    String taskId = task.getSystemAttributes().getTaskId();
    String userInputList = null;
    String[] usersList = null;
    if(this.getUserToAssign().getValue() != null) {
    userInputList = (String) this.getUserToAssign().getValue();
    usersList = userInputList.split(",");
    } else {
    facesMessage = new FacesMessage("No users list provided. Please provide atleast one userId to reassign the task(s). ");
    facesContext.addMessage(null, facesMessage);
    return;
    }

    for(int j=0; j<usersList.length; j++) {
    String userToAssign = usersList[j];
    userToAssign = userToAssign.trim();
    if(userToAssign!=null) {
    UserBean userBean = new UserBean();
    boolean isUserValid = userBean.isValidUser(userToAssign);
    if(isUserValid) {
    List<TaskAssignee> assignees = new ArrayList<TaskAssignee>();
    TaskAssignee assignee = new TaskAssignee(userToAssign, IWorkflowConstants.IDENTITY_TYPE_USER);
    assignees.add(assignee);

    if(taskAction.equals(TASK_ACTION_REASSIGN)) {
    taskSvc.reassignTask(ctx, taskId, assignees) ;
    this.getConfirmMsg().setValue("The task(s) have been reassigned");
    }
    else if(taskAction.equals(TASK_ACTION_DELEGATE)) {
    taskSvc.delegateTask(ctx, taskId, assignees);
    this.getConfirmMsg().setValue("The task(s) have been delegated");
    }
    } else {                       
    if(isFirstInvalidUser)
    errorMessage = errorMessage + " " + userToAssign;
    else
    errorMessage = errorMessage + ", " + userToAssign;
    isFirstInvalidUser = false;
    }
    }
    }


    if(!isFirstInvalidUser) {
    facesMessage = new FacesMessage(errorMessage);
    facesContext.addMessage(null, facesMessage);
    } else {
    this.getConfirmationPopup().show(new RichPopup.PopupHints());
    }


    }

    }
    catch (Exception e) {
    //Handle any exceptions raised here...
    System.out.println("Caught workflow exception: "+e.getMessage());
    }
    }


    But, when I supply multiple uses separated by comma(,), the tasks are being assigned to the last user ONLY. Any idea why its happening.

    Thanks.
  • 7. Re: Assign tasks automatically when vacation set for a user
    868989 Newbie
    Currently Being Moderated
    Its working when I move the below code out of the for loop ( for(int j=0; j<...................)

    if(taskAction.equals(TASK_ACTION_REASSIGN)) {
    taskSvc.reassignTask(ctx, taskId, assignees) ;
    this.getConfirmMsg().setValue("The task(s) have been reassigned");
    }
    else if(taskAction.equals(TASK_ACTION_DELEGATE)) {
    taskSvc.delegateTask(ctx, taskId, assignees);
    this.getConfirmMsg().setValue("The task(s) have been delegated");
    }

    Thanks

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points