AnsweredAssumed Answered

Saving variables/data for incomplete user tasks

Question asked by texens on Jun 18, 2014
Latest reply on Jun 18, 2014 by ashendra1
Hi,

My usecase is following : I have a large form (User Task). I'm expecting the user to fill this form over a period of couple of days. I need the ability to save the local variables for the task even though the task might not be complete.

There are two ways of doing this -

a) Every time the user fills up one field in the browser, I update the local variable via REST update local variable call (http://activiti.org/userguide/index.html#N14C0C)

b) Have a Java service task for validating that all the required fields have indeed been entered. If all the fields have been put in, proceed to next task, else save the local task variables and throw an activiti exception. Eg. https://www.evernote.com/shard/s352/sh/d4a07f09-03d1-48c7-812a-38a5146ba016/d817c394e0aca41f3f80b5064f5116ec

I'm trying to implement the *b* option, as *a* would require too many PUT calls to the REST API (one for each variable).
But for some reason, <b>I'm unable to save the local variable in the java service task</b>. Is there some rule in Activiti, that if a Java Service Task throws an activiti exception during execution, we roll back all changes to local variables ?

My Java Service Task looks like this :

        String processId = execution.getProcessInstanceId();
        TaskService tkService = execution.getEngineServices().getTaskService();
        List<Task> ltasks = tkService.createTaskQuery().processInstanceId(processId).list();
        Task task = ltasks.get(0);
        String taskId = task.getId();
       
        TaskService taskService = execution.getEngineServices().getTaskService();

        // Set local variable
        taskService.setVariableLocal(taskId, "mobile", execution.getVariable("mobile"));

        // throw Activiti Exception
        throw new ActivitiException(error);


Anybody got any ideas as to what could be the probable reason here ?
This seems like a somewhat common usecase, is there a more appropriate way of solving this problem in general ?

TIA

Outcomes