# Using DmnHistoryService

**URL:** <https://forum.flowable.org/t/using-dmnhistoryservice/7620>\
**Category:** Flowable Engine\
**Created:** [March 18, 2021, 9:24am UTC](https://forum.flowable.org/t/using-dmnhistoryservice/7620 "2021-03-18T09:24:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![asaizu](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@asaizu](https://forum.flowable.org/u/asaizu)\
**Post date:** [March 18, 2021, 9:24am UTC](https://forum.flowable.org/t/using-dmnhistoryservice/7620/1 "2021-03-18T09:24:21Z")

</div>

Hello! I am trying to understand how the Historic Decision are retrieved.

I am first executing a rule decision:

```
dmnRuleService.createExecuteDecisionBuilder().decisionKey(DECISION_KEY)
                .variables(flowableQuery)
                .executeWithAuditTrail()
                .getDecisionResult()

```

And after that I am trying to get the history for the above executed decision

```
List<DmnHistoricDecisionExecution> history = dmnHistoryService.createHistoricDecisionExecutionQuery()
                .decisionKey(DECISION_KEY).list();

```

And this list comes empty.  
Am I missing something?

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [March 18, 2021, 9:38am UTC](https://forum.flowable.org/t/using-dmnhistoryservice/7620/2 "2021-03-18T09:38:46Z")

</div>

That looks like it should work. Where/how are you calling these methods? Could it be you’re calling this at a moment the transaction of the first method hasn’t completed yet (e.g in a JavaDelegate)?

---

<div class="post-metadata">

**Author:** ![asaizu](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@asaizu](https://forum.flowable.org/u/asaizu)\
**Post date:** [March 18, 2021, 9:40am UTC](https://forum.flowable.org/t/using-dmnhistoryservice/7620/3 "2021-03-18T09:40:49Z")

</div>

I am doing it inside a test, should I try and give it some time to finish the transaction?

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [March 18, 2021, 9:44am UTC](https://forum.flowable.org/t/using-dmnhistoryservice/7620/4 "2021-03-18T09:44:26Z")

</div>

No, that shoud be ok. Can you share your test?

---

<div class="post-metadata">

**Author:** ![asaizu](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@asaizu](https://forum.flowable.org/u/asaizu)\
**Post date:** [March 18, 2021, 9:47am UTC](https://forum.flowable.org/t/using-dmnhistoryservice/7620/5 "2021-03-18T09:47:15Z")

</div>

Sure!

```
@MicronautTest
@Testcontainers
@Property(name = "flowable.rules-location", value = "rules/dummy_risk_locations.dmn")
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class FlowableDummyRulesTest {
    public static final String COUNTRY = "country";
    public static final String CONTRACT_TYPE = "contractType";
    public static final String CLASS_OF_BUSINESS = "classOfBusiness";
    public static final String EXISTING_COUNTRY = "US";
    public static final String EXISTING_CONTRACT_TYPE = "INSURANCE";
    public static final String EXISTING_CLASS_OF_BUSINESS = "MOVEABLE";
    private static final String DECISION_KEY = "RISK_LOCATIONS";

    @Inject
    DmnHistoryService dmnHistoryService;

    @Inject
    DmnRuleService dmnRuleService;

    @Test
    void executeRuleWithResult() {

        List<Map<String, Object>> decisionResult = queryFlowable(buildQueryMap());
        List<DmnHistoricDecisionExecution> history = dmnHistoryService.createHistoricDecisionExecutionQuery()
                .decisionKey(DECISION_KEY).list();

        assertFalse(decisionResult.isEmpty());
        assertFalse(history.isEmpty());
    }

    private List<Map<String, Object>> queryFlowable(Map<String, Object> flowableQuery) {
        return dmnRuleService.createExecuteDecisionBuilder().decisionKey(DECISION_KEY)
                .variables(flowableQuery)
                .executeWithAuditTrail()
                .getDecisionResult();
    }

    private Map<String, Object> buildQueryMap() {
        return Map.of(COUNTRY, EXISTING_COUNTRY, 
                CONTRACT_TYPE, EXISTING_CONTRACT_TYPE, 
                CLASS_OF_BUSINESS, EXISTING_CLASS_OF_BUSINESS);
    }

}
```

---

<div class="post-metadata">

**Author:** ![asaizu](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@asaizu](https://forum.flowable.org/u/asaizu)\
**Post date:** [March 18, 2021, 2:11pm UTC](https://forum.flowable.org/t/using-dmnhistoryservice/7620/6 "2021-03-18T14:11:10Z")

</div>

Found anything? 😄
