Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In that case, there are two possible cost types: investment and operational. Each investment is approved by InvestAdmin, so in the first row, InvestAdmin approves each investment, so there is only one condition and suited result in the first row. In the next rows, cost types are blank, so that parameter is ignored. For IT Department there are two possibilities - costs with higher amount (equal or higher than 20000) are approved by one of the IT Directors, cheaper is approved by any IT Manager approves cheaper. In the end - every non-investment cost created by Board is approved by one of the board members.

All expenditures are declared via JIRA. To report costs, the concerned create new issues. After checking all data, he can proceed with a task and the approver should be designated automatically.

...

Code Block
languagegroovy
themeRDark
@WithPlugin([
		"eu.rivetgroup.atlas.rvg-jira-app-base-plugin",
		"eu.rivetgroup.atlas.rvg-jira-decision-tables-plugin"
])

Firstly, there is an import of required functionalities from add-ons.

...

Code Block
languagegroovy
themeRDark
TestCostDecisionTablePostFunction(Map<String, Object> transientVars, boolean validatorMode) {
	super(transientVars, validatorMode, false)
}

A constructor , it provides required data about workflow.

...

References to related fields. We strongly suggest to exclude excluding such relations to the external file, what which will help you get a higher quality.

Thanks to them, we can get possible operations for all fields needed to call decision tables and process the result. Field operations allows to allow taking no care about the particular field type in many scenarios - code is much less complex and easier to read.

...

Build the decision table query - to declared fields in the decision table, we add values. Cost Type and Cost Center are the single choice options, so we provide the first BusinessKey (current option value), . The amount is a numerical, so we use ObjectValue.

...

Execution of query on the decision table. To get the Decision Table Operation instance, we use "costDecisions" as a name of the Decision Table file (with .dmn extension) and "costDecision" as an id of decision table element inside the DMN model , because DMN can contain multiple decision tables.

...

Set the context related to the executed decision table. Thanks to that, we have an info about the decision table name or query, which helps to handle many any errors.

Code Block
languagegroovy
themeRDark
Map<String, ?> dtResEntry = dtResult.singleNonEmpty()

Next, we get an entry as a map with output parameters from the result. Here we use singleNonEmpty , because we expect a single entry from the table, other . Other cases should be reported as incorrect. 

Code Block
languagegroovy
themeRDark
String approverGroupName = dtResEntry.get("approverGroup")
String approverUser = dtResEntry.get("approver")
groupAssigneeField.setValueByBusinessKey(approverGroupName)
if (approverUser != null) {
	assigneeField.setValueByBusinessKey(approverUser)
}
return true

At the finish, we fill related fields in the issue with obtained values. We use the method setValueByBusinessKey , because it ensures us if important conditions are checked. For more information, see Technical documentation.

Additionally, we return true, because the postfunction post-function works properly.

Attachments

...