Managed Parent Rule Type

Managed Parent Rule Type
lac32
When you insert a child object, managed parent rules insert a parent object if it does not already exist. This rule uses the following algorithm:
  1. You insert a child object. The logic engine checks whether there are any managed parent rules for that entity.
  2. If there are, then for each such rule the following occurs:
    • If the foreign key in the child object is null or incomplete, then nothing happens.
    • If the foreign key in the child object is complete, then the engine looks in the database to verify that the corresponding parent exists.
    • If the parent exists, then nothing happens.
    • If the parent does not exist, API Creator creates the parent and establishes the relationship between the two by copying the attributes used in the foreign key from the child into the new parent.
  3. Optionally, API Creator hands the new parent to your JavaScript code for further initialization.
    Note: 
    You do not need to write any code, unless you want to initialize the parent object beyond what is done automatically.
  4. API Creator inserts the new parent into the database.
You can access the 
row
 , 
oldRow
 , 
logicContext
, and 
parent
 variables by providing initialization code. The 
row
 and 
oldRow
 variables refer to the child object being modified.
The 
parent
 variable contains the new parent object API Creator is going to insert. You can modify this new parent object before API Creator inserts it through the 
parent
 variable. For example, you might need to compute the values for required attributes.
You cannot access the new parent object through the 
row
 variable.
Processed prior to Row Logic
Managed parent occurs before row logic. You cannot compute foreign keys using formulas.
For more information about logic execution and generated primary key handling, see Logic Execution.
Common Use Case - Group By
You can store subtotals that are incrementally maintained as updates occur, using the 
GroupBy
 pattern. For example, you can track total sales for each sales rep each month. A common use case is to use managed parents for grouping totals. The managed parent is defined as follows.
For more information about viewing an example of the managed parent rule type, see the Group By Rollup example in the Reactive Logic Tutorial.
You can test this by posting the following to 
PartnerOrder
 and verifying that rows are created in 
empsales
:
{
"isReady": false,
"approving_officer": "G PO.1",
"salesrep_name": "A. Lincoln",
"customer": "Gloria's Garden",
"LineItems": [
{
"productName": "Hammer",
"quantityOrdered": 1
}
]
}