Page tree
Skip to end of metadata
Go to start of metadata

Creation decision table using Camunda Modeler

For instructions on how to create a DMN decision table in Camunda Modeler, please check: https://docs.camunda.org/get-started/quick-start/decision-automation/#create-a-dmn-table-using-the-camunda-modeler

Adding decision table file to Jira

In the current version, the add-on supports decision tables saved in Camunda format (.dmn) which you could prepare in the Camunda Modeler application. To use them, put them into the plugin folder on your Jira server:

  1. Go to the JIRA HOME directory.
  2. If you can't find the decision_tables directory, create a new one.
  3. Go to the decision_tables directory.
  4. Put there your decision table files.

Using decision table in a groovy script

Let's use a known us example:

Additionally, let's assume we can save cost as an issue in our Jira - columns correspond to custom fields. Based on that it can be concluded, who will be responsible and set that in an appropriate field. Using Decision Table for Jira add-on we can do that with such script in ScriptRunner Console.

Example scripts

import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import eu.rivetgroup.atlas.jira.plugins.decisiontables.api.DecisionTableManager

// get DecisionTableManager which is an OSGI component in the Decision Tables plugin
@WithPlugin("eu.rivetgroup.atlas.rvg-jira-decision-tables-plugin")
@PluginModule
DecisionTableManager decisionTableManager

// build a decision table query, fill input parameters values
def dtQuery = [
		"costType": "Investment",
		"costCentre": "1500 - IT Department",
		"amount": 2000
]

// execute the decision table query
def dtResult = decisionTableManager.getDMNDecisionTableOperations(
		"costDecisions", // name of the DMN file without the file extension (dmn)
		"costDecision" // id of decision table element inside DMN model (DMN can contain multiple decision tables)
).executeQuery(dtQuery);

// get entry from the result, this is a map with the output parameters of matched entries 
// there is chosen singleNonEmpty, because we expect single result, other should be reported as an error
Map<String, ?> dtResEntry = dtResult.singleNonEmpty()

// get an username of approver
String approverName = dtResEntry.get("approver")
return approverName

Of course, you don't want to execute Decision Tables for Jira functionalities manually, but use them to automatize your business processes. So let's look at another example, where we want to automatically set that approver as an assignee to that issue. Such script can be used as a post-function on your workflow.

def customFieldManager = ComponentAccessor.getCustomFieldManager()

// get involved custom field references
def costTypeCF = customFieldManager.getCustomFieldObjectsByName("Cost Type").first()
def costCentreCF = customFieldManager.getCustomFieldObjectsByName("Cost Centre").first()
def amountCF = customFieldManager.getCustomFieldObjectsByName("Amount").first()

// get field values
def costType = (Option) issue.getCustomFieldValue(costTypeCF)
def costCentre = (Option) issue.getCustomFieldValue(costCentreCF)
def amount = (Double) issue.getCustomFieldValue(amountCF)

// get DecisionTableManager which is an OSGI component in the Decision Tables plugin
@WithPlugin("eu.rivetgroup.atlas.rvg-jira-decision-tables-plugin")
@PluginModule
DecisionTableManager decisionTableManager

// build a decision table query, fill input parameters values
def dtQuery = [
	"costType": costType.value, // single choice option filed - we pass an option value
	"costCentre": costCentre.value, // single choice option filed - we pass an option value
	"amount": amount // numerical value - use the value directly
]

// execute the decision table query
def dtResult = decisionTableManager.getDMNDecisionTableOperations(
	"costDecisions", // name of the DMN file without the file extension (dmn)
	"costDecision" // id of decision table element inside DMN model (DMN can contain multiple decision tables)
).executeQuery(dtQuery);

// get returned entry from the result
Map<String, ?> dtResEntry = dtResult.singleNonEmpty();

// we get user name of approver
String approverName = dtResEntry.get("approver")

def approverUser  = ComponentAccessor.getUserManager().getUserByName(approverName)

// set assginee as approverUser
issue.setAssignee(approverUser)
  • No labels