Rule Language Cheat Sheet

One page with the whole AwareIM rule language: the rule shape, the conditions, the most used actions and functions, about 20 ready patterns and the mistakes people make most. Every item links to its full page.

IF (RuleCondition) THEN
    ActionList
ELSE IF (RuleCondition) THEN
    ActionList
ELSE
    ActionList

IF and ELSE are optional. A rule with only actions is an unconditional rule. See Rule Definition.

Write Meaning
Account.State attribute of an object
Account.Type.Name attribute of a referred object (any depth)
3, 5.6 number
'CLOSED' string (apostrophes, not quotes)
`CLOSED` string with backticks (the key under ~): use it when the text holds apostrophes
05/12/98 date (dd/mm/yy)
05/12/98 17:05 date/time (dd/mm/yy HH:mm)
2w3d10:45 duration (weeks, days, hours:minutes)
UNDEFINED empty value

See Literal.

Join conditions with AND / OR. Put NOT ( … ) around a condition to negate it.

Pattern Example
compare: =, <, >, <=, >=, <> Account.Balance < Account.Type.MinBalance + 100
text Account.Name STARTSWITH 'John' (also ENDSWITH, CONTAINS)
one of these values Account.State IN 'Open', 'Closed'
range (both ends included) Account.Balance BETWEEN 10000 AND 20000
empty / filled Account.State IS UNDEFINED / Account.State IS DEFINED
object is being created Message IS NEW
value changed Account.State WAS CHANGED, Account.State WAS CHANGED TO 'Open'
list changed Transaction WAS ADDED TO Account.Transactions, Transaction WAS REMOVED FROM Account.Transactions, Transaction FROM Account.Transactions WAS CHANGED
any object exists EXISTS Account WHERE (Account.State = 'Open')
object is in a reference list Transaction IN Account.Transactions
user is logged in SystemUser IN LOGGED_IN_USERS
negate NOT (Account.State IN 'OPEN', 'CLOSED', 'SUSPENDED')

See Rule Condition.

SUM, COUNT, MIN, MAX, AVG, with an optional WHERE (…):

SUM Account.Balance WHERE (Account.State='OPEN')
COUNT Account WHERE (Account.State='Open')

See Aggregate Operation.

Write Result
'John' + ' ' + 'Smith' John Smith (strings join with +)
'Number' + Account.Balance a string, e.g. Number1000
Account.OpeningDate + 7 the date 7 days later
Transaction.Timestamp - 3 the timestamp 3 hours earlier
Account.Balance - Transaction.Amount an UNDEFINED value is left out (result = Account.Balance)

See Notes on rule execution.

Use these when the Context holds more than one instance of the same object.

Prefix Means
This the first instance in the Context (e.g. the object the rule belongs to)
That the second instance (usually found by FIND or made by CREATE)
Other all instances after the first
LoggedIn the user who is logged in, e.g. LoggedInAssociate
Added, Removed, Changed the list item that was added, removed or changed
Failed the object that made a process fail

See Instance Prefixes.

Action Example
assign Account.State = 'Open', Member.Loans = UNDEFINED
INCREASE / REDUCE INCREASE Account.Balance BY 1000, REDUCE Account.Balance BY 5%
CREATE CREATE Account WITH Account.State='Open', Account.Balance=0
FIND FIND Account WHERE Account.State = 'Open', FIND ALL Account, FIND 'Open accounts' (a query)
DELETE DELETE Account
INSERT / REMOVE INSERT Transaction IN Account.Transactions, REMOVE Transaction FROM Account.Transactions
REPORT ERROR REPORT ERROR 'Account with non-zero balance cannot be closed'
PROTECT PROTECT Transaction FROM ALL EXCEPT Administrator
SEND SEND ReservationOfferNotification TO Reservation.Member VIA Email
DISPLAY MESSAGE DISPLAY MESSAGE 'Items have been created'
DISPLAY QUESTION DISPLAY QUESTION 'Do you want to print out a receipt?'
VIEW VIEW Account USING 'Some fancy form'
START PROCESS START PROCESS Object.Attribute
EXEC_SQL EXEC_SQL `SELECT CRM_Customer WHERE FirstName='Jane'` RETURN Customer

All actions: Actions.

Function Example
CURRENT_DATE Account.OpeningDate=CURRENT_DATE
CURRENT_TIMESTAMP Transaction.Time = CURRENT_TIMESTAMP
DATE_ADD (days) DATE_ADD (Account.OpeningDate, 4)
MONTH_ADD MONTH_ADD (Account.OpeningDate, 4)
DAY_DIFFERENCE DAY_DIFFERENCE (Account.OpeningDate, Account.ClosingDate)
YEAR_DIFFERENCE YEAR_DIFFERENCE (Account.OpeningDate, Account.ClosingDate)
AGE AGE (Account.Customer.DateOfBirth) > 70
LENGTH LENGTH (Account.Name)
SUBSTRING SUBSTRING (Account.Name, 0, 4) (second index not included)
INDEX_OF INDEX_OF ('Smith', Account.Name) (0 = not found)
TO_UPPER_CASE TO_UPPER_CASE (Account.Name)
TRIM TRIM (Account.Name)
AS_STRING / AS_NUMBER AS_STRING (Account.Number), AS_NUMBER (Account.Text)
ROUND ROUND (6.738, 2) = 6.74
LIST_SIZE LIST_SIZE (Client.Children) > 2
OLD_VALUE OLD_VALUE (Account.Balance)

All functions: All Functions.

IF Account.State='CLOSED' AND Account.Balance<>0 THEN
    REPORT ERROR 'Account with non-zero balance cannot be closed'
IF EXISTS SystemUser WHERE (SystemUser.LoginName = ThisSystemUser.LoginName) THEN
    REPORT ERROR 'User with this name already exists'
IF Account.Type IS UNDEFINED THEN
    FIND AccountType WHERE AccountType.Name='Credit' Account.Type=AccountType
CreditAccount.AvailableFunds = CreditAccount.CreditLimit+CreditAccount.Balance-CreditAccount.NonClearedFunds
IF Transaction WAS ADDED TO Account.Transactions THEN
    INCREASE Account.Balance BY AddedTransaction.Amount
IF Transaction WAS REMOVED FROM Account.Transactions THEN
    REDUCE Account.Balance BY RemovedTransaction.Amount
IF Transaction FROM Account.Transactions WAS CHANGED THEN
    INCREASE Account.Balance BY (ChangedTransaction.Amount - OLD_VALUE(Transaction.Amount))
IF NOT (Message IS NEW) THEN PROTECT Message.Subject
IF Transaction.State='APPLIED' THEN
    PROTECT Transaction FROM ALL EXCEPT Administrator

Users cannot change the field, but processes can:

IF Account.STATE <> 'NEW' THEN
    PROTECT Account.Balance FROM ALL EXCEPT System

Hide records completely (not read from the system):

IF Transaction.State='APPLIED' THEN
    READ PROTECT Transaction FROM ALL
IF Account.State WAS CHANGED TO 'Open' THEN ...
CREATE Account WITH Account.State='Open', Account.Balance=0

One record per day of a period:

CREATE Transaction FOR EACH DAY BETWEEN Account.OpeningDate AND Account.ClosingDate WITH Transaction.AppliedDate=LOOP_ITERATION
FIND ALL Account ORDER BY Account.Balance DESC TAKE BEST 5
FIND Account WHERE Account.State = 'OPEN' AND Account.Balance > 1000 ORDER BY Account.Balance IN BATCHES OF 5
DISPLAY QUESTION 'Do you want to print out a receipt?' YESNAME 'I do' NONAME 'I do not'
IF Question.Reply = 'Yes' THEN ...
DISPLAY MESSAGE ASYNCH BOTTOM_LEFT 'Items have been created'
SEND ReservationOfferNotification TO Reservation.Member VIA Email

From a specific email account (an EmailAccount object in the Context):

SEND ReservationOfferNotification TO Reservation.Member USING EmailAccount
IF LoggedInAssociate.LoginName='john' THEN DoSomething

  • Strings use apostrophes: 'Open'. A query name with spaces also needs them: FIND 'Open accounts'.
  • Strings only support +. Yes/No and Document attributes cannot be used in calculations.
  • <, >, <=,>= only work on numbers, dates and durations.
  • In comparisons an UNDEFINED value counts as 0.
  • BETWEEN includes both ends.
  • A condition on a reference list (Customer.Policies.CarType='Wagon') is true when any item in the list matches.