ILOG JRules User Guide > Creating Rule Projects > Tasks > Defining How Business Elements Map to the XOM > Accessing Functions from IRL Mapping Code

You can access functions from the IRL mapping code. Extender mapping does not allow you to do this.

To access functions:

  1. In the Outline view, click the member that contains the IRL mapping you want to edit.
  2. In the BOM Editor, open the BOM to XOM Mapping section, and go to the IRL statement in the Body field.
  3. Use the method IlrContext.invokeFunction to access the function.
  4. Save the BOM.

For example, suppose you have a BOM class ShoppingCart with an attribute public readonly double averageItemPrice.

In your rule project, there is a function that computes the average price of the items in a shopping cart:

function double computeAveragePrice(ShoppingCart cart) {
   if (cart.numberOfItems != 0)
    return cart.value / cart.numberOfItems;
  return 0;
}

This IRL function is based on the BOM, not the XOM.

To map the averageItemPrice attribute to a call to the computeAveragePrice function, you can write the following IRL mapping code for the attribute averageItemPrice:

Double result = (Double) invokeFunction("computeAveragePriceShopping",
                                        new Object[] {this});
return result.doubleValue();

Related Concepts

Business Object Model (BOM)
Execution Object Model (XOM)
BOM and XOM

Related Tasks

Defining How Business Elements Map to the XOM
Managing XOM Changes in the BOM

Related Reference

BOM Editor
ILOG Rule Language

Related Samples and Tutorials

Tutorial: Defining a Vocabulary