# Dynamic decision table execution

**URL:** https://forum.flowable.org/t/dynamic-decision-table-execution/7809
**Category:** Flowable Engine
**Created:** [May 2, 2021, 6:21pm UTC](https://forum.flowable.org/t/dynamic-decision-table-execution/7809 "2021-05-02T18:21:41Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![DrStone92](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/drstone92/32/2376_2.png) [@DrStone92](https://forum.flowable.org/u/DrStone92)
#### Post date: [May 2, 2021, 6:21pm UTC](https://forum.flowable.org/t/dynamic-decision-table-execution/7809/1 "2021-05-02T18:21:41Z")

</div>

I am looking for a possibility to execute a buch of rules against an event that comes in, which has the rules defined in its payload. I took the rules (json) and created DmnDefinition with DmnJsonConverter.

The piece of code I tried to leverage on : [Programmatically create decisions tables and run cases against it - #22 by yvo](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/22)

It works it tests, I got an output variable with result, but if I place this code in Service Task in BPMN process, then I got an exception that says : “No decision found for key: decisionnew2 and tenantId: abcd.”.

I just need this decision table to be executed once against the event. Every new event comes with new set of rules, based on which I have to create new decision table.

Where I made a mistake ? Do you think my approach is correct, or this scenario could be approached better ?

---

<div class="post-metadata">

### Author: ![yvo](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/yvo/32/2231_2.png) [@yvo](https://forum.flowable.org/u/yvo)
#### Post date: [May 3, 2021, 6:50am UTC](https://forum.flowable.org/t/dynamic-decision-table-execution/7809/2 "2021-05-03T06:50:36Z")

</div>

Hi,

When you get that error it means you created a `decision task`; which a specific implementation of a `service task`. This has additional properties available where you can define the decision key (which will be used to lookup and execute the decision at runtime).  
But if I understand correctly you dynamically create, deploy and run a decision at runtime.  
In this case you should use a ‘plain’ service task which has your implementation assigned to it.

Yvo

---

<div class="post-metadata">

### Author: ![DrStone92](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/drstone92/32/2376_2.png) [@DrStone92](https://forum.flowable.org/u/DrStone92)
#### Post date: [May 3, 2021, 12:37pm UTC](https://forum.flowable.org/t/dynamic-decision-table-execution/7809/3 "2021-05-03T12:37:08Z")

</div>

Hi Yvo,

Thanks for quick reply on this.

Yes, I dynamically create, deploy and execute. Everything happens within a Service Task.

![Screenshot from 2021-05-03 14-27-35](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/9/9e4e62e2d0614aea685ccde55faf4221ec56cdac.png)

```
    ObjectMapper mapper = new ObjectMapper();
    JsonNode rules = mapper.readTree((String) delegateExecution.getVariable("rules"));
    DmnDefinition dmnDefinition = new DmnJsonConverter().convertToDmn(rules, "abcd", 1, new Date());

    DmnRepositoryService dmnRepositoryService = dmnEngine.getDmnRepositoryService();

    String dmnDeploymentId = dmnRepositoryService
            .createDeployment()
            .name("newdeployment2")
            .tenantId("abcd")
            .addDmnModel("abc.dmn", dmnDefinition)
            .deploy()
            .getId();
    DmnDecisionService dmnRuleService = dmnEngine.getDmnDecisionService();

    Map<String, Object> inputVariables = new HashMap<>();
    inputVariables.put("input", "ABC");
    inputVariables.put("input2", "CBA");

    Map<String, Object> result = dmnRuleService.createExecuteDecisionBuilder()
            .decisionKey("decisionnew2")
            .tenantId("abcd")
            .variables(inputVariables)
            .executeWithSingleResult();

```

This gives me trouble when kicked off by event, no issues running as test tho.

---

<div class="post-metadata">

### Author: ![yvo](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/yvo/32/2231_2.png) [@yvo](https://forum.flowable.org/u/yvo)
#### Post date: [May 3, 2021, 1:28pm UTC](https://forum.flowable.org/t/dynamic-decision-table-execution/7809/4 "2021-05-03T13:28:50Z")

</div>

Hi,

are you sure the decision has the key `decisionnew2`?

---

<div class="post-metadata">

### Author: ![DrStone92](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/drstone92/32/2376_2.png) [@DrStone92](https://forum.flowable.org/u/DrStone92)
#### Post date: [May 3, 2021, 2:43pm UTC](https://forum.flowable.org/t/dynamic-decision-table-execution/7809/5 "2021-05-03T14:43:29Z")

</div>

Hi,

I just double checked - it is.

I have pushed my code to repo : [GitHub - DrStone92/flowable-decision](https://github.com/DrStone92/flowable-decision)

Would you be so kind to have a look ?

---

<div class="post-metadata">

### Author: ![yvo](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/yvo/32/2231_2.png) [@yvo](https://forum.flowable.org/u/yvo)
#### Post date: [May 3, 2021, 2:57pm UTC](https://forum.flowable.org/t/dynamic-decision-table-execution/7809/6 "2021-05-03T14:57:40Z")

</div>

I will. But can you fix the issues on your example project first? There seem to be some non functional issues in the project and tests.

---

<div class="post-metadata">

### Author: ![DrStone92](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/drstone92/32/2376_2.png) [@DrStone92](https://forum.flowable.org/u/DrStone92)
#### Post date: [May 3, 2021, 3:25pm UTC](https://forum.flowable.org/t/dynamic-decision-table-execution/7809/7 "2021-05-03T15:25:18Z")

</div>

Should be fixed now. Sorry for inconvenience.

EDIT:  
I have dug a little deeper, and it seem that DataSource bean has to be defined. For some reason it does not work with **in memory** h2. “Physical” database has to be used.

---

<div class="post-metadata">

### Author: ![yvo](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/yvo/32/2231_2.png) [@yvo](https://forum.flowable.org/u/yvo)
#### Post date: [May 4, 2021, 7:51am UTC](https://forum.flowable.org/t/dynamic-decision-table-execution/7809/8 "2021-05-04T07:51:35Z")

</div>

Okay. So it’s solved now?  
I had a look at the code and the Flowable part looks okay.  
H2 works too… so if you experience issues with that it must be related to some other parts.

Yvo

---

<div class="post-metadata">

### Author: ![DrStone92](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/drstone92/32/2376_2.png) [@DrStone92](https://forum.flowable.org/u/DrStone92)
#### Post date: [May 4, 2021, 1:33pm UTC](https://forum.flowable.org/t/dynamic-decision-table-execution/7809/9 "2021-05-04T13:33:56Z")

</div>

Yvo,

It works when I define datasource like `dataSourceBuilder.url("jdbc:h2:~/test");`

However it throws an error when I specify `dataSourceBuilder.url("jdbc:h2:mem:flowable;DB_CLOSE_DELAY=-1");`

Not sure why is that happening.

---

<div class="post-metadata">

### Author: ![yvo](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/yvo/32/2231_2.png) [@yvo](https://forum.flowable.org/u/yvo)
#### Post date: [May 4, 2021, 2:00pm UTC](https://forum.flowable.org/t/dynamic-decision-table-execution/7809/10 "2021-05-04T14:00:09Z")

</div>

What error?  
This should be fine.

---

<div class="post-metadata">

### Author: ![DrStone92](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/drstone92/32/2376_2.png) [@DrStone92](https://forum.flowable.org/u/DrStone92)
#### Post date: [May 4, 2021, 4:00pm UTC](https://forum.flowable.org/t/dynamic-decision-table-execution/7809/11 "2021-05-04T16:00:37Z")

</div>

> [@DrStone92](#):
>
> “No decision found for key: decisionnew2 and tenantId: abcd.”.

This one. Like the DmnDefinition would not be deployed using in memory h2.

---

<div class="post-metadata">

### Author: ![yvo](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/yvo/32/2231_2.png) [@yvo](https://forum.flowable.org/u/yvo)
#### Post date: [May 4, 2021, 4:04pm UTC](https://forum.flowable.org/t/dynamic-decision-table-execution/7809/12 "2021-05-04T16:04:40Z")

</div>

And that you can reproduce in a unit test?
