# Programmatically create decisions tables and run cases against it

**URL:** <https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187>\
**Category:** Flowable Engine\
**Created:** [January 7, 2019, 9:41am UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187 "2019-01-07T09:41:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gaurav-israni](https://avatars.discourse-cdn.com/v4/letter/g/91b2a8/32.png) [@gaurav-israni](https://forum.flowable.org/u/gaurav-israni)\
**Post date:** [January 7, 2019, 9:41am UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/1 "2019-01-07T09:41:35Z")

</div>

Hi, I need to create decision tables in back-end, deploy them and test cases against the decision table. I am stuck on which services to use. Can you please help me in how to go about it?

---

<div class="post-metadata">

**Author:** ![Robinyo](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@Robinyo](https://forum.flowable.org/u/Robinyo)\
**Post date:** [January 7, 2019, 12:13pm UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/2 "2019-01-07T12:13:28Z")

</div>

> which services to use

Which API are you planning to use? The REST API?

What have you tried so far?

---

<div class="post-metadata">

**Author:** ![gaurav-israni](https://avatars.discourse-cdn.com/v4/letter/g/91b2a8/32.png) [@gaurav-israni](https://forum.flowable.org/u/gaurav-israni)\
**Post date:** [January 7, 2019, 12:26pm UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/3 "2019-01-07T12:26:51Z")

</div>

I was thinking of creating the decision table using flowable-ui-modeler. Then deploying it using DMN rest API. But I am new to flowable and JAVA . So I am not sure if am going in the right path. I am open to different implementations. Please help.

---

<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:** [January 7, 2019, 12:34pm UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/4 "2019-01-07T12:34:43Z")

</div>

Hi.  
It really depends on the use case.  
Do you want / need to create te decision tables programatically? Or can they be created separately in using the Modeler?  
With ‘test cases’ do you mean using unit tests?  
Is there requirement to deploy via REST or can I it also be deploying using the Java services? (F.e. during bootup)

Regards,

Yvo

---

<div class="post-metadata">

**Author:** ![gaurav-israni](https://avatars.discourse-cdn.com/v4/letter/g/91b2a8/32.png) [@gaurav-israni](https://forum.flowable.org/u/gaurav-israni)\
**Post date:** [January 7, 2019, 12:47pm UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/5 "2019-01-07T12:47:38Z")

</div>

Hi thank you for the quick reply, yes I want to create decision tables programatically. No they cannot be created separately using the Modeler.  
By test cases I mean, I have to execute decision table against set of input. No I don’t mean unit tests.  
I can deploy using either, REST or Java services. What do you recommend?

---

<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:** [January 7, 2019, 1:00pm UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/6 "2019-01-07T13:00:18Z")

</div>

You can create the decision (/ decision table) programatically by constructing a org.flowable.dmn.model.DmnDefinition.  
That can be used when creating a org.flowable.dmn.api.DmnDeploymentBuilder (addDmnModel) and deploy the decision.  
The deployed decision can be executed using one of the execute methods of org.flowable.dmn.api.DmnRuleService.

This way you can construct the Decision Table … deploy it … and control the input variables in code.

Tip: Take a look at the unit tests to see some examples how to execute decision tables and handle the results;

> **[flowable/flowable-engine](https://github.com/flowable/flowable-engine/tree/master/modules/flowable-dmn-engine/src/test)**
>
> A compact and highly efficient workflow and Business Process Management (BPM) platform for developers, system admins and business users. - flowable/flowable-engine

Hope this helps.

Regards,

Yvo

---

<div class="post-metadata">

**Author:** ![gaurav-israni](https://avatars.discourse-cdn.com/v4/letter/g/91b2a8/32.png) [@gaurav-israni](https://forum.flowable.org/u/gaurav-israni)\
**Post date:** [January 8, 2019, 1:20pm UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/7 "2019-01-08T13:20:54Z")

</div>

HI yvo, thanks for the quick reply and help. I have created the DmnDefinition from the json using flowable.editor.dmn.converter.DmnJsonConverter. I would however require some help in deploying it using org.flowable.dmn.api.DmnDeploymentBuilder (addDmnModel). I am not understanding how to use it. Please help in this case.  
Thanks

---

<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:** [January 8, 2019, 1:43pm UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/8 "2019-01-08T13:43:47Z")

</div>

Hi.

Did you take a look at the unit tests I mentioned in my previous reply? There is code there that does similar stuff.

But; you could something like this;

```
dmnRepositoryService.createDeployment().name("exampleDeployment")
        .addDmnModel("exampleDecision", dmnDefinition)
        .deploy();

```

I hope this helps.

Regards,

Yvo

---

<div class="post-metadata">

**Author:** ![gaurav-israni](https://avatars.discourse-cdn.com/v4/letter/g/91b2a8/32.png) [@gaurav-israni](https://forum.flowable.org/u/gaurav-israni)\
**Post date:** [January 8, 2019, 6:20pm UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/9 "2019-01-08T18:20:26Z")

</div>

HI yvo,  
Thanks for your help. I followed the steps you suggested and the deployment was made. But there was no entry created in `ACT_DMN_DECISION_TABLE` and hence I am not able to execute the decision because it needs executes with the help of key. An entry is made in the models ACTACT\_DMN\_DEPLOYMENT and ACT\_DMN\_DEPLOYMENT\_RESOURCE but not in ACT\_DMN\_DEPLOYMENT\_RESOURCE. Do you have any idea about that ?

Thanks again.

---

<div class="post-metadata">

**Author:** ![gaurav-israni](https://avatars.discourse-cdn.com/v4/letter/g/91b2a8/32.png) [@gaurav-israni](https://forum.flowable.org/u/gaurav-israni)\
**Post date:** [January 9, 2019, 7:51am UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/10 "2019-01-09T07:51:19Z")

</div>

![Screenshot%20from%202019-01-09%2013-23-27](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex035/uploads/flowable/original/2X/e/efaa8a3bebe939dc9fc74a9340e43d4261f6375e.png)

This is my DB entry for ACT\_DMN\_DEPLOYMENT\_RESOURCE which has a deployed decision with id : decisionnew2.

But when I try to execute it using dmnRuleService, it is unable to find the decision.  
Code I have written:  
DmnRuleService dmnRuleService = dmnEngine.getDmnRuleService();  
Map\<String, Object\> inputVariables = new HashMap\<\>();  
inputVariables.put(“date1”, new Date());  
inputVariables.put(“date2”, new Date());  
Map\<String, Object\> result = dmnRuleService.createExecuteDecisionBuilder()  
.decisionKey(“decisionnew2”).tenantId(“abcd”)  
.variables(inputVariables)  
.executeWithSingleResult();

It is giving the following exception  
org.flowable.common.engine.api.FlowableObjectNotFoundException: no decisions deployed with key ‘decisionnew2’ for tenant identifier ‘abcd’

Does the dmnRuleService look in some other table to execute the result ?  
Please have a look and help.

---

<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:** [January 9, 2019, 8:27am UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/11 "2019-01-09T08:27:02Z")

</div>

Did you open a seperate topic for this?  
Please keep it contained in one thread.

[https://forum.flowable.org/t/unable-to-execute-decisions-using-dmnruleservice/3201](https://forum.flowable.org/t/unable-to-execute-decisions-using-dmnruleservice/3201)

How did you deploy the table? And is the tenant correct?

Regards,

Yvo

---

<div class="post-metadata">

**Author:** ![gaurav-israni](https://avatars.discourse-cdn.com/v4/letter/g/91b2a8/32.png) [@gaurav-israni](https://forum.flowable.org/u/gaurav-israni)\
**Post date:** [January 9, 2019, 9:06am UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/12 "2019-01-09T09:06:49Z")

</div>

Yes I opened a separate topic. Yes I will close that one.

I deployed it by writing the following code :

DmnDeploymentdmnDeployment=dmnRepositoryService.createDeployment().name(“newdeployment2”).tenantId(“abcd”).addDmnModel(“dmn\_example2”, dmnDefinition).deploy();

Yes the tenant is correct. Also I had tried deploying without tenant also and then executing also without teant. It gave me the same error.

Also I tried dmnRepositoryService.createDecisionTableQuery().list() . It gave an empty list.  
I don’t understand the entries are there in ACT\_DMN\_DEPLOYMENT and ACT\_DMN\_DEPLOYMENT\_RESOURCE but not in ACT\_DMN\_DECISION\_TABLE. I thought entries are created in all these models after deployment.

---

<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:** [January 9, 2019, 9:20am UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/13 "2019-01-09T09:20:13Z")

</div>

Could you share the complete Java code so I can check it for errors / completeness (and not pseudo code)?

So; the way you read the JSON; create the DmnDefinition; deploy and execute.

---

<div class="post-metadata">

**Author:** ![gaurav-israni](https://avatars.discourse-cdn.com/v4/letter/g/91b2a8/32.png) [@gaurav-israni](https://forum.flowable.org/u/gaurav-israni)\
**Post date:** [January 9, 2019, 9:35am UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/14 "2019-01-09T09:35:06Z")

</div>

Sure, following is the code:

ObjectMapper objectMapper = new ObjectMapper();  
try {  
JsonNode decisionTableNode = objectMapper.readTree("{\n" +  
" “id”: “8dd36898-4c56-11e7-9d73-a26608126000”,\n" +  
" “modelVersion”: “2”,\n" +  
" “name”: “Dates134”,\n" +  
" “key”: “decisionnew2”,\n" +  
" “hitIndicator”: “FIRST”,\n" +  
" “inputExpressions”: [\n" +  
" {\n" +  
" “id”: “1”,\n" +  
" “variableId”: “date1”,\n" +  
" “variableType”: null,\n" +  
" “type”: “date”,\n" +  
" “label”: “Date One”,\n" +  
" “entries”: [],\n" +  
" “newVariable”: false\n" +  
" },\n" +  
" {\n" +  
" “id”: “3”,\n" +  
" “variableId”: “date2”,\n" +  
" “variableType”: null,\n" +  
" “type”: “date”,\n" +  
" “label”: “Date Two”,\n" +  
" “entries”: [],\n" +  
" “newVariable”: false\n" +  
" }\n" +  
" ],\n" +  
" “outputExpressions”: [\n" +  
" {\n" +  
" “id”: “2”,\n" +  
" “variableId”: “output1”,\n" +  
" “variableType”: null,\n" +  
" “type”: “date”,\n" +  
" “label”: “Output One”,\n" +  
" “entries”: [],\n" +  
" “newVariable”: false\n" +  
" }\n" +  
" ],\n" +  
" “rules”: [\n" +  
" {\n" +  
" “2”: “is 14/06/2017”,\n" +  
" “1\_operator”: “==”,\n" +  
" “1\_expression”: “14-06-2017”\n" +  
" },\n" +  
" {\n" +  
" “1\_operator”: “!=”,\n" +  
" “1\_expression”: “16-06-2017”,\n" +  
" “2”: “not 16/06/2017”\n" +  
" }\n" +  
" ]\n" +  
“}”);  
DmnDefinition dmnDefinition = new DmnJsonConverter().convertToDmn(decisionTableNode,“abcd”, 1, new Date());  
DmnEngine dmnEngine = DmnEngines.getDefaultDmnEngine();  
DmnRepositoryService dmnRepositoryService = dmnEngine.getDmnRepositoryService();  
DmnDeployment dmnDeployment = dmnRepositoryService.createDeployment().name(“newdeployment2”).tenantId(“abcd”)  
.addDmnModel(“dmn\_example2”, dmnDefinition)  
.deploy();  
DmnRuleService dmnRuleService = dmnEngine.getDmnRuleService();  
Map\<String, Object\> inputVariables = new HashMap\<\>();  
inputVariables.put(“date1”, new Date());  
inputVariables.put(“date2”, new Date());  
Map\<String, Object\> result = dmnRuleService.createExecuteDecisionBuilder()  
.decisionKey(“decisionnew2”).tenantId(“abcd”)  
.variables(inputVariables)  
.executeWithSingleResult();

---

<div class="post-metadata">

**Author:** ![gaurav-israni](https://avatars.discourse-cdn.com/v4/letter/g/91b2a8/32.png) [@gaurav-israni](https://forum.flowable.org/u/gaurav-israni)\
**Post date:** [January 9, 2019, 11:07am UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/15 "2019-01-09T11:07:14Z")

</div>

Hi tvo, Any update ?

---

<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:** [January 9, 2019, 12:48pm UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/16 "2019-01-09T12:48:22Z")

</div>

Yes 😉

I had some issue running your code because of encoding issues in your paste.

The resource name has to end with “dmn”, “dmn.xml”, “dmn11” or “.dmn11.xml”.  
So f.e.

`.addDmnModel(“dmn_example2.dmn”, dmnDefinition)`

A naming convention for deployed resources is needed in order to differentiate them.

Let me know if this helps.

Yvo

---

<div class="post-metadata">

**Author:** ![gaurav-israni](https://avatars.discourse-cdn.com/v4/letter/g/91b2a8/32.png) [@gaurav-israni](https://forum.flowable.org/u/gaurav-israni)\
**Post date:** [January 10, 2019, 5:36am UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/17 "2019-01-10T05:36:41Z")

</div>

Thank You Yvo. It worked 🙂 Thank you so much.

---

<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:** [January 10, 2019, 8:42am UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/18 "2019-01-10T08:42:07Z")

</div>

NP. Thanks for the feedback.

---

<div class="post-metadata">

**Author:** ![gaurav-israni](https://avatars.discourse-cdn.com/v4/letter/g/91b2a8/32.png) [@gaurav-israni](https://forum.flowable.org/u/gaurav-israni)\
**Post date:** [January 11, 2019, 5:48am UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/19 "2019-01-11T05:48:18Z")

</div>

Hi yvo, just a quick question, How do we run flowable’s rest API’s on our local system/server.

---

<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:** [January 11, 2019, 8:42am UTC](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187/20 "2019-01-11T08:42:13Z")

</div>

Hi,

There are several ways to deploy and run the Flowable REST APIs.  
OOTB you can run the Flowable REST web app (deploy the WAR or run the Docker container)  
Or when you’re running the Flowable Task web app. The REST API’s are exposed there.

Or you can include them yourself in your custom app. F.e. using the Spring Boot starters.

Regards,

Yvo

[Next page](https://forum.flowable.org/t/programmatically-create-decisions-tables-and-run-cases-against-it/3187.md?page=2)
