Item Object

We have defined two calculated attributes for the Item object – “Available” and “CurrentReservation” (see “Calculated Attributes” section above), so we need to define two rules that calculate these attributes.

An item is available if it is not on loan, if it is not reserved and if it is not withdrawn by the library. Otherwise the item is not available. The “not on loan” condition means that there is no loan in the Current state associated with the item. Using the Rule Language this condition can be written as:

NOT (EXISTS Loan WHERE (Loan IN Item.Loans AND Loan.Status='Current')) 

The condition that there is no current reservation associated with the item, can be written like so:

Item.CurrentReservation IS UNDEFINED 

The entire rule can therefore be written like so:

IF NOT (EXISTS Loan WHERE ( Loan IN Item.Loans AND Loan.Status='Current')) AND Item.CurrentReservation IS UNDEFINED AND Item.InternalStatus='Released' THEN 
  Item.Available='Yes'
 ELSE 
  Item.Available='No'
 

The rule that calculates the current reservation needs to sort all waiting or offered reservations associated with the item by the reservation date and take the one with the most recent date. In the Rule Language this can be written as:

FIND Reservation WHERE Reservation IN Item.Reservations AND (Reservation.Status='Waiting' OR  Reservation.Status='Offered') ORDER BY Reservation.ReservedOn TAKE BEST 1 
 Item.CurrentReservation=Reservation 

We should also consider the fact that we should only do this if we do not already have the current reservation that has been offered but not taken up. This condition can be written as:

Item.CurrentReservation.Status<>'Offered' 

The entire rule therefore can be written like this:

IF Item.CurrentReservation.Status<>'Offered' THEN 
   FIND Reservation WHERE Reservation IN Item.Reservations AND (Reservation.Status='Waiting' OR Reservation.Status='Offered') ORDER BY Reservation.ReservedOn TAKE BEST 1 
   Item.CurrentReservation=Reservation 

Note that when writing these rules we do not need to concern ourselves with the circumstances under which these rules should be executed, nor different scenarios that lead to the execution of these rules1). We focus entirely on the rules of the object and rely on the system to trigger the rules whenever necessary.

Let us now enter these rules into Aware IM. To do this double click on the node of the Item business object in the Elements Tree and select the “Update Rules” tab at the bottom of the screen. Click on the icon to create a new rule. Enter the name of the rule “Item availability”. A new empty rule will appear in the list. We will see the rule editor underneath the list. The editor consists of 2 tabs – the “Standard Form” tab and the “Textual Form” tab. Both tabs allow entering the text of the rule – the “Standard Form” has a simplified interface but does not allow entering rules in certain formats, whereas the Textual Form allows entering any rules (see also the “Adding/Editing Rules” section. In this example we will use the “Textual Form”. Click on the “Textual Form” tab and enter the first rule exactly as described above into the text area of the tab, enter the name of the rule “Item availability” and click on the icon. In a similar fashion enter the second rule (with the name “Current reservation”). Click on the “Save” button in the toolbar (or select File/Save from the menu) to save changes to the rules.

The rules for the Item object have been entered. There are no more rules for this object.


1)
We should keep in mind though that the rules are triggered when the instance of the object is created or modified. Our two rules therefore will always be executed whenever this happens. If we are concerned about performance we could optimise the rules slightly and for the second rule, for example, add a condition that will guarantee that the rule is only executed when there is a change in the list of reservations of the item or a reservation belonging to this list is modified (if the list of reservations does not change the rule will not change anything either). The condition looks like so:
IF Item.Reservations WAS CHANGED OR Reservation FROM Item.Reservations WAS CHANGED 
  • Last modified: 2022/09/13 18:15