Guidelines on How to Be Groovy

You use the Groovy scripting language when you write your rule text, and you use interfaces in your script to import objects from your configurator model so your script can access them.

Be Groovy

Here are some important Groovy features that you can use when you write your extension rule.

  • Use the def keyword to declare variables without declaring the type of variable.
  • Define methods and variables outside of a class and use them anywhere in your script. Groovy will include them in its ScriptClass class, and will run them in the run method.
    Define Methods in Classes When You Don't Define Methods in Classes When You
    • Prefer to use inheritance and encapsulation in your code.
    • Prefer to build more complex logic, such as you might normally do in the Java programming language.
    • Define a lot of methods. Adding them to a class makes it easier to select them from the Class attribute and the Method attribute when you bind your events.
    Need to write and test code quickly. You can simply bind every event to ScriptClass and run.

For more, see Groovy.

Access Configurator Objects

You use various interfaces to access objects during a runtime configuration. Here are some of the objects that you typically use.

What Your Code Needs to Do Interface That You Use to Access It Code That You Use to Create the Object Example That Uses the Object
Get the event that you specify when you bind the method. ICXEvent No code needed. The script automatically creates the cxEvent object when you run the rule. Get the current configuration that the event references:

IConfiguration config = cxEvent.getConfiguration()

Get the rule's base node. ICXEvent def baseNode = cxEvent.getBaseNode() Test whether your user selected the base node:

if (baseNode.isSelected()) ...

Get the configuration that's active during the runtime session. IConfiguration IConfiguration config = cxEvent.getConfiguration() Get the root node of the configuration that's active during the runtime session:

def root = config.getRootBomModel()

Get the root node that's active during the runtime session. IBomModelInstance IBomModelInstance root = config.getRootBomModel() Get a child node of the model. Use the item name to search the model, such as the AS54888 item, and start searching at the root node:

def childItem = root.getChildByName("AS54888")

Oracle Configurator automatically initializes each object that's involved with the event that you bind. This object is an instance of the ICXEvent interface named cxEvent.

Manage Node Values

You can get and set the values for various objects on each node. Here are some examples.

Type of Feature Java Interface Code That Gets the Value Code That Sets the Value
Integer IIntegerFeature int getValue() void setIntValue(int value)
Decimal IDecimalFeature double getValue() void setDecimalValue(double value)
Option IOptionFeature IOption getSelectedOption() void select()
Boolean IBooleanFeature boolean isSelected() void toggle()

Many more interfaces are available to meet your specific needs. For example:

  • Get and set logic states
  • Access properties
  • Access options
  • Override contradictions
  • Manage logical contradictions
  • Manage exceptions

The oracle.apps.scm.configurator.runtime.core package contains the classes that you can use to interact with Configurator. For details, go to https://docs.oracle.com/, then search for Java API Reference for Oracle Configurator.

Java API Reference for Oracle Configurator only includes objects that Configurator supports in an extension rule. Some Groovy classes contain objects and interfaces that Configurator doesn't support. If your script references a class or interface that Configurator doesn't support, then you will encounter an error when you validate your code. The error identifies the reference that isn't correct.

Groovy can determine the feature's data type at run time, so you don't need to declare the type in your script.