Managing programmable decisions
A programmable decision enables your organization to use JavaScript in a decision model variant and offers the following benefits:
-
Run server-side JavaScript in a decision
-
Include real-time contextual data in decisioning
-
Leverage your organization's custom attributes for use in decision making
Programmable decisions are designed for more technical users who are comfortable writing JavaScript. If this is you, you might consider creating a decision template. A decision template is essentially a programmable decision created by a technical user. Once published, the decision template is enabled on the decision palette for any type of user to drag and drop onto the decision canvas, no code required.
Creating a decision template is a good option if you know the decision will be one that your organization wants to reuse in multiple decision models. The other advantage of creating a decision template is that you can create a form to display to the user, which enables them to further configure the decision, without ever having to write, edit, or see JavaScript.
When writing your JavaScript, you can leverage any variables used in other components including other programmable decisions, knowledge sources, and decision tables. This also includes variables from data systems and analytical models, made available through connections.
When you create a programmable decision, you can assign it an output reference. An output reference is an unique name that represents the output of the programmable decision. The output reference can then be used as an Input into other decision components including decision tables, other programmable decisions, and analytical models made available via connections.
Programmable decisions can also be used in other decision models. For example, you can download the programmable decision and then upload the programmable decision to the intended decision model variant. Alternatively, you can copy the programmable decision and paste it when creating a new programmable decision in a different decision model variant.
Programmable decisions and arrays
Programmable decisions are often used to leverage attributes from an array. Currently, programmable decisions are the only way to leverage nested attributes in decisioning. The programmable decision retrieves the attributes from the array, and another decision, such as a decision table, uses the previously-nested attributes as Input in making a decision.
Structuring programmable decisions
Before you add a programmable decision to a decision model, it's best to familiarise yourself with the recommended code structure. Once you start writing programmable decisions or decision templates, use the Immediately Invoked Function Expression (IIFE), as shown in the following example.
(function () {
statements
})();
IIFE is a JavaScript function that runs as soon as it's defined. The design pattern above prevents accessing variables within the IIFE expression as well as prevents you from having too many globally-accessible defined variables. It's essentially a Self-Executing Anonymous Function with lexical scope enclosed within the Grouping Operator (). See IIFE for more information.