Databases Reference
In-Depth Information
In our example,
TAuctionItem
contains
winningBid
and
bidHistory
(which
contains
bid
), while
TBids
contains
bid
. As mentioned previously, we need to assert
all the
bid
elements contained in
TBids
; we also need to assert the
winningBid
element contained in
TAuctionItem
. To do this, select the checkbox
Tree
(circled in
the last screenshot) for each of these parameters. This will cause the decision function
to parse the top-level element and assert all descendent facts.
At this point, we can actually save and run the ruleset from our auction process.
Assuming everything works as expected, it will return a result containing details of
the actual auction item that we passed in. All that remains now is for us to write the
rules to evaluate our list of bids.
Using a global variable to reference the
resultset
When we configure a decision service, we specify one or more facts that we want the
decision service to
watch
(that is,
AuctionItem
in the previous example); these are
often referred to as the resultset.
Many of our rules within the ruleset will require us to update the resultset. For
example, every time we evaluate a bid, we will need to update the
AuctionItem
fact
accordingly, either to record a bid as the new winning bid or add it to the bid history
as a failed bid.
When a rule is fired, the action block is only able to operate on those facts contained
within its local scope, which are those facts contained in the fact set row for that
activation. Or put more simply, the rule can only execute actions against those facts
that triggered the rule.
This means that for any rule that needs to operate on the resultset, we would need
to include the appropriate test within the rule condition in order to pull that fact into
the fact set row for the activation. So in the case of our Auction ruleset, we would
need to add the following statement to every rule that needed to operate on the
AuctionItem
fact:
AuctionItemisaAuctionItem
This just adds an extra level of complexity to all our rules, particularly if you have
multiple facts contained within the resultset. It's considered a better practice to
define a global variable that references the resultset, which we can access within
the action block of any rule and within any function we define.