2 Replies Latest reply on Dec 5, 2012 12:26 PM by Thomas Setiabudi

    Is there anybody who know how to get a process variable's value when get a task by userid?

    星兰 蒋 Newbie

      Hi JBPM,

       

      SOS!!!!

       

      In my case,in fact i want to get the vars's value when i get a task by userid. And these values are passed when i start a processinstance.

       

      i set & get values all in myself application. no using the jbpm console. Also no using marshall and unmarshall.

       

      Set values when start process:

       

      Map<String,Object> params = new HashMap<String,Object>();
      params.put("sales", c.getCreateby());
      params.put("contractno", c.getContractno());
      params.put("details", c.getDetails());
      params.put("amount", c.getAmount());
      params.put(role.getRole(), leader.getName());
      params.put("accoptor", list.get(0).getName());

      getSession().startProcess(definitionId, params);

       

       

      Get values when get a task by userid:

       

      List<TaskSummary> t = sTaskService.getTasksAssignedAsTaskInitiator(idRef, "en-UK");

       

      if(null != t && t.size() > 0){

       

      for(TaskSummary ts : t){
      Object obj = getTaskContentInput(ts);
      Map<?, ?> map = (Map<?, ?>) obj;
      for (Map.Entry<?, ?> entry : map.entrySet()) {
      System.out.println(entry.getKey() + " = " + entry.getValue());
      }
      tasks.add(new TaskRef(ts.getId(), ts.getProcessInstanceId() + "", ts.getProcessId(),
      ts.getName(), ts.getCreatedBy().getId(), ts.getStatus() == Status.Suspended, ts.getStatus() != Status.Suspended));
      }

       

      }

       

      And the getTaskContentInput method as blow:

       

      public Object getTaskContentInput(TaskSummary taskSum) {

      BlockingGetTaskResponseHandler handlerT = new BlockingGetTaskResponseHandler();

      client.getTask(taskSum.getId(), handlerT);

      Task task2 = handlerT.getTask();

      TaskData taskData = task2.getTaskData();

      BlockingGetContentResponseHandler handlerC = new BlockingGetContentResponseHandler();

      client.getContent(taskData.getDocumentContentId(), handlerC);

      Content content = handlerC.getContent();
      ByteArrayInputStream bais = new ByteArrayInputStream(

      content.getContent());

      try {

      ObjectInputStream is = new ObjectInputStream(bais);

      Object obj = null;

       

      while ((obj = is.readObject()) != null) {

      System.out.println("OBJECT: " + obj);

      return obj;

      }

      } catch (Exception e) {

      System.err.print("There was an error reading task input...");

      e.printStackTrace();

      return null;

      }

      return null;

      }

       

      Is My way right or wrong? Would you pls give some advice?

       

      Thanks and Best Regards!