Create an Extension Rule
Use Groovy to code your extension, bind a Groovy method to an event, bind the method's arguments to a source, then test your work.
Summary of the Setup
- Create your model and supplemental features.
- Create the extension rule.
- Bind your groovy method to an event.
- Bind your method's argument to a source.
- Test your model.
Assume you need to create a model named zCZ_CAR4DRSDN, allow you to specify a value of 20,000 to 60,000 for the list price, then apply a 0% to 10% discount.
This topic includes example values. You might use different values, depending on your business requirements.
Create Your Model and Supplemental Features
- Go to the Configurator Models work area.
- Create a new workspace and set the Effective Start Date to tomorrow. For details, see Manage Your Workspace.
- On the Manage Workspaces page, in the search results, click your new workspace.
- On the Workspace page, click Actions > Select and Add > Models.
-
In the dialog that displays, search for your model, select it, then click OK.
Attribute Value Model zCZ_CAR4DRSDN - In the Workspace Participants area, click zCZ_CAR4DRSDN.
- On the Edit Configurator Model page, select the zCZ_CAR4DRSDN model’s root node, then click Actions > Create > Decimal Feature.
-
In the Dialog that displays, set the values.
Attribute Value Name List Price Minimum 20,000 Maximum 60,000 Domain Ordering System Default -
Click Apply and Create Another, then set the values.
Attribute Value Name Discount Minimum 0 Maximum 10 Domain Ordering System Default -
Click Apply and Create Another, then set the values.
Attribute Value Name Sale Price Minimum 0 Maximum 100,000 Domain Ordering System Default - Click OK, then click Save.
Create the Extension Rule
Create a rule that applies the discount to the list price, then puts the result in the sale price.
- On the Edit Configurator Model page, click Rules.
- Click Actions > Create > Extension Rule.
- In the dialog that displays, set the Name attribute to Apply Discount, then click OK.
- In the Structure area, expand the tree.
- Right-click the Discount node, then click Set as Base Node.
- In the Rule Text area, enter this Groovy
script:
// Import objects from the configurator model. import oracle.apps.scm.configurator.runtime.core.IConfiguration import oracle.apps.scm.configurator.runtime.core.IBomModelInstance import oracle.apps.scm.configurator.runtime.core.IDecimalFeature // Define the method that will apply the discount. def applyDiscount ( p_listPrice, p_discount ) { // Use arguments to get values from the nodes. double listPrice = ((IDecimalFeature)p_listPrice).getValue() double discount = ((IDecimalFeature)p_discount).getValue() double salePrice = 0 // Calculate the price. salePrice = listPrice - ( listPrice * ( discount / 100 ) ) // Get the node where you will set the value. IConfiguration config = cxEvent.getConfiguration() IBomModelInstance root = config.getRootBomModel() IDecimalFeature salePriceNode = root.getChildByName("Sale Price") // Set the value. ((IDecimalFeature)salePriceNode).setDecimalValue(salePrice) }
- Click Save, then click Validate.
Bind Your Method to an Event
-
In the Event Bindings area, click Create, then set the values.
Attribute Value Event postValueChange Event Scope Base Node Class ScriptClass Method applyDiscount
Note that the Method attribute also displays applyDiscount's arguments, such as
p_listPrice
andp_discount
. - Click Save.
Bind Your Method's Argument to a Source
-
In the Argument Bindings area, click the row that has this value.
Name Specification Value p_listPrice Model Node Empty - In the Structure area, right-click the List Price node, then click Set as Argument Value.
-
In the Argument Bindings area, verify that the row now has this value.
Name Specification Value p_listPrice Model Node 'zCZ_CAR4DRSDN'.'List Price' -
In the Argument Bindings area, click the row that has this value.
Name Specification Value p_discount Model Node Empty - In the Structure area, right-click the Discount node, then click Set as Argument Value.
-
In the Argument Bindings area, verify that the row now has this value.
Name Specification Value p_discount Model Node 'zCZ_CAR4DRSDN'.'Discount' - Click Save, click Validate, then click Save and Compile.
Test Your Model
- Click Test Model.
- In the dialog that displays, set the values, then click
OK.
Attribute Value User Interface Default Root Quantity 1 - On the Test Model page, verify that the page displays your new decimal features and
displays them in the same sequence that you used when you added them to your
model:
- List Price
- Discount
- Sale Price
- In the List Price attribute, enter
30,000
. - Verify that you can only enter values starting with 20,000 and up to 60,000. These are the minimum and maximum values that you specified when you created the List Price decimal feature.
- Notice that the Sale Price attribute is empty.
- In the Discount attribute, enter
10
. - Verify that you can only enter values starting with 0 and up to 10. These are the minimum and maximum values that you specified when you created the Discount decimal feature.
- Click Enter in the Discount attribute, then notice that
Oracle Configurator updates the value in the Sale Price attribute from empty to
27,000.
The discount is 10% and the list price is 30,000. 10% of 30,000 equals 3,000, and 30,000 minus 3,000 equals 27,000.
- Enter
20
in the Discount attribute, then notice that the Sale Price attribute now contains 24,000.Configurator applies this change because you bound the extension rule to the event that happens when you change the value of the Discount attribute.
- Enter
20,000
in the List Price attribute.Notice that Configurator doesn't update the Sale Price. That's because you didn't bind the rule to an event that happens when you change the List Price’s value.
In an actual implementation, you would probably also bind the rule to the List Price. We don't do it here to illustrate how the logic works. To test your knowledge, you can set up that bind and see if it works.
- Click Finish.