Rule Types

Rule Types
lac51
You can create the following rule types in API Creator:
Rule Type
Description
Code Examples
Derive attribute value by summing designated child attribute, with optional child qualification condition.
Qualification is in SQL Where syntax.
Derive 
Customer.balance
 as:
Sum(ordersList.amount_un_paid where is_ready = true)
Sum(children where anAttribute != null)
Derive attribute value by counting designated child rows using a defined relationship, with optional child qualification condition.
Qualification is in SQL Where syntax.
Derive 
Customer.big_order_count
 as:
Count(ordersList where amount_total > 100)
Derive an attribute value using other attributes in that entity, or parent entity (changes are propagated). For conditional assignment, use JavaScript if/else or the ternary operator ((boolean)
?[true value]:[else value]
).
Formula rules can access the values of the current row (
row.attribute
 values), the old row (
oldRow.attribute
 values), and the current values of parent rows. They must not access the values of grandparent rows. You can specify state transition logic (for example, logic based on data changes) using formula rules.
Formula rules return a value which is appropriate for its column. For example, a formula rule for a string column must return a string. API Creator converts numeric types automatically as needed.
For more information:
  • About how to access row attributes and parent-relationship attributes using Expression help, see Customize your API.
  • About the list of code examples that are available for formula rules, see JavaScript Code Examples.
Derive 
Lineitem.amount
 as:
return row.part_price * row.quantity_ordered
Derive 
product_billofmaterials.value
 as:
return row.kit_number_required * row.product.price
Derive 
order.DueDate
 as:
if (row.due_date === null) {
return new Date(moment(row.placed_date).add('months', 1)
else
return row.due_date; // no change
If a formula rule returns nothing, then the value of the column is unchanged:
if (row.value > 1000) // Do not change
return;
Derive attribute value from parent attribute value (unlike formula references, parent changes are not propagated).
Derive 
Lineitem.Price
 as:
ParentCopy(product.price)
Multi-attribute expression of class/parent attributes that must be met for a transaction to succeed. They return true (else exception message is thrown). They can execute as transaction rows are processed or at commit time so your validation code sees the results of all rule executions for all rows (for example, sums and counts). They must evaluate to a boolean value.
Validations rules can access the values of the current row (
row.attribute
 values), the old row (
oldRow.attribute
 values), and the current values of parent rows. You can specify state transition logic (for example, logic based on data changes) using formula rules, validation rules, and actions.
For more information about the list of code examples that are available for validation rules, see JavaScript Code Examples.
Validate 
Customer.CheckCredit
 as:
row.balance < row.credit_limit
Validate 
Purchaseorder.NotEmpty
 on commit as:
return row.item_count > 0
Commit validation (see Validation Rule Type)
References derivation results.
Invoke JavaScript action (often an extensible service); can execute during or after row processing, or on a commit (after all rows are processed).
Event rules are JavaScript that 
CA Live API Creator
 executes whenever a row is inserted, updated, or deleted (when you have enabled the rule for that type of event).
For more information:
See the example for 
allocateFromTo
 system method. For more information, see The allocateFromTo System Method.
Early event (see Event Rule Types)
Fires before your logic executes. The row data has not yet been subjected to formulas and other derivations. You can change the row, and the changes are automatically subjected to validations, other chained logic, and saved.
Commit event (see Event Rule Types)
Fires after row-logic is completed for all the rows in the transaction. The rows reflect logic processing. You cannot change the rows. Typical usage: send an email.
Pre-insert event (see Event Rule Types)
For inserts, fires when 
CA Live API Creator
 maps resource rows to table rows. This occurs in advance of the other event rules and is typically used to compute primary keys.
You can have 
CA Live API Creator
 generate alphanumeric primary keys using pre-insert event rules that computes the keys.
For more information about how to compute an alphanumeric primary key with sequences, see Oracle Sequence Example API Sample.
You do not need to create pre-insert event rules for database-generated primary keys. The database handles these keys automatically.
Derive value as the min/max of designated child rows, with optional child qualification condition.
Derive 
Customer.maxOrder
 as:
max(ordersList where is_ready = true)
Automatically insert a parent object if it does not already exist.
Create parent for GroupBy, for example, 
empsales
 to track total sales for employee each month.