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

  1. Create your model and supplemental features.
  2. Create the extension rule.
  3. Bind your groovy method to an event.
  4. Bind your method's argument to a source.
  5. 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

  1. Go to the Configurator Models work area.
  2. Create a new workspace and set the Effective Start Date to tomorrow. For details, see Manage Your Workspace.
  3. On the Manage Workspaces page, in the search results, click your new workspace.
  4. On the Workspace page, click Actions > Select and Add > Models.
  5. In the dialog that displays, search for your model, select it, then click OK.

    Attribute Value
    Model zCZ_CAR4DRSDN
  6. In the Workspace Participants area, click zCZ_CAR4DRSDN.
  7. On the Edit Configurator Model page, select the zCZ_CAR4DRSDN model’s root node, then click Actions > Create > Decimal Feature.
  8. In the Dialog that displays, set the values.

    Attribute Value
    Name List Price
    Minimum 20,000
    Maximum 60,000
    Domain Ordering System Default
  9. Click Apply and Create Another, then set the values.

    Attribute Value
    Name Discount
    Minimum 0
    Maximum 10
    Domain Ordering System Default
  10. Click Apply and Create Another, then set the values.

    Attribute Value
    Name Sale Price
    Minimum 0
    Maximum 100,000
    Domain Ordering System Default
  11. 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.

  1. On the Edit Configurator Model page, click Rules.
  2. Click Actions > Create > Extension Rule.
  3. In the dialog that displays, set the Name attribute to Apply Discount, then click OK.
  4. In the Structure area, expand the tree.
  5. Right-click the Discount node, then click Set as Base Node.
  6. 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)
    }
    
  7. Click Save, then click Validate.

Bind Your Method to an Event

  1. 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 and p_discount.

  2. Click Save.

Bind Your Method's Argument to a Source

  1. In the Argument Bindings area, click the row that has this value.

    Name Specification Value
    p_listPrice Model Node Empty
  2. In the Structure area, right-click the List Price node, then click Set as Argument Value.
  3. In the Argument Bindings area, verify that the row now has this value.

    Name Specification Value
    p_listPrice Model Node 'zCZ_CAR4DRSDN'.'List Price'
  4. In the Argument Bindings area, click the row that has this value.

    Name Specification Value
    p_discount Model Node Empty
  5. In the Structure area, right-click the Discount node, then click Set as Argument Value.
  6. In the Argument Bindings area, verify that the row now has this value.

    Name Specification Value
    p_discount Model Node 'zCZ_CAR4DRSDN'.'Discount'
  7. Click Save, click Validate, then click Save and Compile.

Test Your Model

  1. Click Test Model.
  2. In the dialog that displays, set the values, then click OK.
    Attribute Value
    User Interface Default
    Root Quantity 1
  3. 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
  4. In the List Price attribute, enter 30,000.
  5. 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.
  6. Notice that the Sale Price attribute is empty.
  7. In the Discount attribute, enter 10.
  8. 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.
  9. 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.

  10. 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.

  11. 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.

  12. Click Finish.