# Completing a process with History level == NONE

**URL:** <https://forum.flowable.org/t/completing-a-process-with-history-level-none/2020>\
**Category:** Flowable Engine\
**Created:** [May 14, 2018, 3:54pm UTC](https://forum.flowable.org/t/completing-a-process-with-history-level-none/2020 "2018-05-14T15:54:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![franck102](https://avatars.discourse-cdn.com/v4/letter/f/35a633/32.png) [@franck102](https://forum.flowable.org/u/franck102)\
**Post date:** [May 14, 2018, 3:54pm UTC](https://forum.flowable.org/t/completing-a-process-with-history-level-none/2020/1 "2018-05-14T15:54:12Z")

</div>

Hi all,

I am trying to use the engine with the history level set to none, and I am having trouble a) making sure that the process completed normally and b) retrieving the final value of a process variable from the process instance. The code I use looks like this:

```
ProcessInstance instance = _processEngine.getRuntimeService().startProcessInstanceByKey(...);
if (instance.isEnded()) {
    // how do I check for normal termination, i.e. reaching an end event, as opposed to a 
    // canceled process for example?
    return ((ExecutionEntity)instance).getVariableInstance(variableName).getValue();
}

```

… and I would like to avoid the downcast to ExecutionEntity: is there a way to navigate to the instance’s execution without going through queries (which don’t return anything because history level is NONE)?

Thanks!  
Franck

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [May 15, 2018, 7:05am UTC](https://forum.flowable.org/t/completing-a-process-with-history-level-none/2020/2 "2018-05-15T07:05:17Z")

</div>

Hi Franck,

```
public void testStartEndProcess() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("StartEndProcess");
    assertThat(processInstance.isEnded(), is(true));
    assertThat(((ExecutionEntity) processInstance).getExecutions().get(0).getActivityId(), is("theEnd"));
}

```

Works fine. You want to avoid downcast. You are right, queries are empty because of history level NONE.  
One possibility could be to add a listener to the end event which will write variable value and process end state to the structure which is accessible form outside of the process scope (in memory or in the DB). That’s one possibility. I am not saying the best one. 🙂

Martin

---

<div class="post-metadata">

**Author:** ![franck102](https://avatars.discourse-cdn.com/v4/letter/f/35a633/32.png) [@franck102](https://forum.flowable.org/u/franck102)\
**Post date:** [May 15, 2018, 7:19am UTC](https://forum.flowable.org/t/completing-a-process-with-history-level-none/2020/3 "2018-05-15T07:19:06Z")

</div>

Thanks Martin, I like the listener idea, I will experiment with that.

Regarding the  
((ExecutionEntity) processInstance).getExecutions().get(0).getActivityId(), is(“theEnd”)

suggestion, I see two issues with it:

- is it guaranteed that getExecutions().get(0) will always return the execution in which the end event was reached?
- I don’t know the activityId of the end event (or end events since there could be several), I would need to scan the process beforehand to find that out…

Franck

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [May 15, 2018, 8:09am UTC](https://forum.flowable.org/t/completing-a-process-with-history-level-none/2020/4 "2018-05-15T08:09:58Z")

</div>

> [@franck102](#):
>
> is it guaranteed that getExecutions().get(0) will always return the execution in which the end event was reached?

No it depends on the process instance state and definition

> [@franck102](#):
>
> I don’t know the activityId of the end event (or end events since there could be several), I would need to scan the process beforehand to find that out…

yes, but Ids are specified in the definition.

Martin

---

<div class="post-metadata">

**Author:** ![franck102](https://avatars.discourse-cdn.com/v4/letter/f/35a633/32.png) [@franck102](https://forum.flowable.org/u/franck102)\
**Post date:** [May 15, 2018, 8:20am UTC](https://forum.flowable.org/t/completing-a-process-with-history-level-none/2020/5 "2018-05-15T08:20:40Z")

</div>

Right… so overall the listener approach seems much simpler and more reliable 🙂

Thanks!  
Franck

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [May 15, 2018, 8:47am UTC](https://forum.flowable.org/t/completing-a-process-with-history-level-none/2020/6 "2018-05-15T08:47:18Z")

</div>

May be small improvement could be to add the listener automatically to the end activity during process parsing. In that case you can be sure that nobody will forget it.  
[https://www.flowable.org/docs/userguide/index.html#advanced\_parseHandlers](https://www.flowable.org/docs/userguide/index.html#advanced_parseHandlers)
