You can create rules using JavaScript in a Decision Table
component.
Before you begin
To perform this task, you must be in the IBM® Process
Designer desktop editor, which is deprecated.
About this task
The following steps describe how to create a sample business
rule using the Decision Table editor and JavaScript. The rule in the
sample is used to determine whether approval is required for certain
employee expenses. The sample is a single-function rule that can be
called from any other service. For your own implementation, you might
not use the same steps or names.
Procedure
- Open the Process Designer desktop editor (deprecated).
- Open a process application that contains a business process definition (BPD).
- Create a Decision service.
- Drag a Decision Table component from the palette to the
Decision service diagram, and edit the component parameters as described
in the related topic "Adding a Decision Table component to a service."
- Click the Decisions tab to open
the rules editor.
- In the rules editor, click the plus sign to add a variable
(column) to the first rule (row).
- From the variables displayed, pick the amount variable
from the request structure.
- Type >250 as the value.
- In the rules editor, click the plus sign again. Make sure
the first rule (row) is selected because you want to add another variable
(column) to this rule.
- From the variables displayed, pick the type variable
from the request structure.
- Type "director" as the value.
- In the Action Requirement field
for the first rule (row), type Requires Approval.
- In the rules editor, click the Action section
to expand it.
- For the Requires Approval requirement, enter the following
JavaScript code for the Action: tw.local.approvalRequired
= true; The rules editor includes the rule shown
in the following image:
- In the rules editor, click the second row to select it.
Create a new rule so that expenses of more than $60 for employees
requires approval.
- In the rules editor, click the third row to select it.
Create your catch-all condition by typing - for both
the amount and type. The - value in a
variable field indicates that any variable value is considered a match.
- In the Action Requirement field
for the third rule (row), type Auto Approval.
- In the Action section, enter the
following JavaScript for the Auto Approval action: tw.local.approvalRequired
= false; The rules editor includes the rules shown
in the following image:
For more information
about specifying variable values using JavaScript, refer to the related
topic "Specifying variable values using JavaScript."
- Click the Diagram tab.
- Use the Sequence Flow tool to connect the Decision Table
component and the Start and End events.
- Name the Decision Table component and save your work.
What to do next
You can now nest this Decision service in any other service
within your process application that requires this logic. Be sure
to adjust the input and output variables as required for each implementation.
For more information about the controls in the decisions
editor window, such as the up and down arrows, refer to the related
topic "Decision Table controls."