Rules and Functions

If you are using the source editor, adapt these instructions that focus on the form-based editor and mention the equivalent settings in the source editor.

Rule Form Editor

Rule Source Editor
 * @description
 * @author
 */
rule Rules.ProcessDebits.ApplyDebit {
  attribute {
    priority = 1;
    forwardChain = true;
Optionally add entry for Rank as needed (Rank=RuleFunction), or enter in Form view.
  }
  declare {
    Events.Debit  debit;
    Concepts.Account  account;
  }
  when {
    //Checks whether the extId of an Account instance in working memory
    //matches the incoming event's account ID
    account@extId == debit.AccountId;
  }
  then {
    //If Account Status is not Suspended, debits the account
    if (account.Status !="Suspended") {
    account.Debits=debit.Amount;
    System.debugOut("############### Debiting account <" +account@extId+ "> by $" +debit.Amount);
    account.Balance=account.Balance - debit.Amount;
    System.debugOut("############### New balance: $" + account.Balance);
    }
    else {
    System.debugOut("############### Cannot debit the suspended acount <" +account@extId +">");
    }
    Event.consumeEvent(debit);
  }
}