cancel
Showing results for 
Search instead for 
Did you mean: 

Saving variables/data for incomplete user tasks

texens
Champ in-the-making
Champ in-the-making
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/d817c394e0aca41f3f80b506...

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
1 REPLY 1

ashendra1
Champ in-the-making
Champ in-the-making
Combine the two solution,

When the user is submitting the task, break it in two parts, first make a rest call to save the variable and then form data submit to move on to the next task. The next task will validate the data. If data validation service throws the exception, you didn't moved to a next task and current data is being saved.

In such cases one should always, create a draft copy of the variable, make changes in these and do validation over this only, so that old data can be reloaded at any time.