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

Business description

To facilitate cost approval process, our company decided to auto-fill data, which are use in process.

Solution Brief

In that company, each user is related to exactly one department and one cost center. Based on an issue author, we can specify his HR number, department or related cost center, which will be useful in next steps. We can add another postfunction, which can indicate them.

Example Decision Table

Script

Note

In this script we use some superclasses, which help us in code management. For more information, see Usage of base groovy classes and utilities page.

import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import global.fields.CustomFieldCode
import global.fields.FieldUtils
import global.fields.SystemFieldId

@WithPlugin([
		"eu.rivetgroup.atlas.rvg-jira-app-base-plugin",
		"eu.rivetgroup.atlas.rvg-jira-decision-tables-plugin"
])
class TestSetEmployeeDataPostFunction extends BaseDecisionTableWorkflowFunction {

	TestSetEmployeeDataPostFunction(Map<String, Object> transientVars, boolean validatorMode) {
		super(transientVars, validatorMode, false)
	}

	@Override
	protected boolean executeInternal() {
		def reporterField = issueFieldOperator.forField(FieldUtils.getSystemField(SystemFieldId.REPORTER))
		def employeeHRNumberField = issueFieldOperator.forField(FieldUtils.getCustomField(CustomFieldCode.EMPLOYEE_HR_NUMBER))
		def departmentField = issueFieldOperator.forField(FieldUtils.getCustomField(CustomFieldCode.DEPARTMENT_CF))
		def costCentreField = issueFieldOperator.forField(FieldUtils.getCustomField(CustomFieldCode.COST_CENTRE))

		issueFieldOperator.checkRequired(reporterField);

		def dtResult = decisionTableManager.getDMNDecisionTableOperations(
				"employees", 
				"employeeData"
		).executeQuery([
				"user": reporterField.getBusinessKey().first()
		])
		issueFieldOperator.getConfig().setCurrentExecutionInfo(dtResult.executionContextInfo)

		Map<String, Object> dtResEntry = dtResult.singleNonEmpty()
		employeeHRNumberField.setObjectValue(dtResEntry.get("employeeHRNumber"))
		departmentField.setValueByBusinessKey(dtResEntry.get("department"))
		costCentreField.setValueByBusinessKey(dtResEntry.get("costCentre"))

		return true;
	}
}

Explanation

@WithPlugin([
	"eu.rivetgroup.atlas.rvg-jira-app-base-plugin",
	"eu.rivetgroup.atlas.rvg-jira-decision-tables-plugin"
])
class TestSetEmployeeDataPostFunction extends BaseDecisionTableWorkflowFunction{

TestSetEmployeeDataPostFunction(Map<String, Object> transientVars, boolean validatorMode) {
	super(transientVars, validatorMode, false)
}

In that case, we also start with point depended imports and define a constructor.

def reporterField = issueFieldOperator.forField(FieldUtils.getSystemField(SystemFieldId.REPORTER))
def employeeHRNumberField = issueFieldOperator.forField(FieldUtils.getCustomField(CustomFieldCode.EMPLOYEE_HR_NUMBER))
def departmentField = issueFieldOperator.forField(FieldUtils.getCustomField(CustomFieldCode.DEPARTMENT_CF))
def costCentreField = issueFieldOperator.forField(FieldUtils.getCustomField(CustomFieldCode.COST_CENTRE))
issueFieldOperator.checkRequired(reporterField);

References to related fields and addition of the validation, if necessary fields have values. Without them, operations could be impossible.

def dtResult = decisionTableManager.getDMNDecisionTableOperations(
	"employees",
	"employeeData"
).executeQuery([
	"user": reporterField.getBusinessKey().first()
])
issueFieldOperator.getConfig().setCurrentExecutionInfo(dtResult.executionContextInfo)

Execution of one parameter query on the decision table. To get Decision Table Operation instance we use "employees" as a name of Decision Table file (with .dmn extension) and "employeeData" as an id of decision table element inside DMN model, because DMN can contain multiple decision tables. Next, we set the context related to executed decision table. Thanks to that we have an info about decision table name or query, which helps to handle many errors.

Map<String, Object> dtResEntry = dtResult.singleNonEmpty()
employeeHRNumberField.setObjectValue(dtResEntry.get("employeeHRNumber"))
departmentField.setValueByBusinessKey(dtResEntry.get("department"))
costCentreField.setValueByBusinessKey(dtResEntry.get("costCentre"))

At finish, we get an entry as a map with output parameters from the result and use obtained values to fill related fields in issue.

Attachments

TestSetEmployeeDataPostFunction.groovyemployees.dmn

  • No labels