Set Up Row Context for Property Rule Conditions
A page can display multiple records of the same object. Each record may require different behavior based on its data—for example, enabling an action for some phone or address records and disabling it for others.
Row context is the current record’s data that can be used when defining a property rule’s condition. As an application developer, you define row context to make selected record fields available in the page property rule condition editor. Conditions that use row context let the same page property return different values based on each record’s data. Here, “row” refers to an individual record in a set of records, such as a list; it does not require a table.
As the application developer, you configure two parts in Advanced mode: the artifact’s JSON defines which fields users can select when creating conditions, and the HTML binding supplies the current item’s data when evaluating the property.
| Piece | Purpose |
|---|---|
propertyRulesRowContextShape in JSON |
Describes available fields, their labels, types, and selectable values. |
$withEnv({ row: item.data }) in HTML |
Supplies the current item’s actual data when reading the property. |
| Row Context in the condition builder | Lets users select those fields to define when a rule applies. |
Before you begin, make sure your page has an extendable, rules-backed constant and a repeated-row template with access to the current record. The following example assumes that you already have a Boolean constant named isEditable, with a default value of true, and a phones variable containing records with phoneType and number fields. These names and values are examples; use the identifiers and data values defined in your application.
To set up row context for a page property:
-
In the factory extension, open the page’s JSON file and add
propertyRulesRowContextShapeto the top-level@dtobject.For example, merge the following metadata into the page’s existing JSON, preserving its other definitions. If the file already contains an
@dtobject, add the property to that object rather than creating a second one.{ "@dt": { "propertyRulesRowContextShape": { "phoneType": { "label": "Phone Type", "type": "string", "enum": ["Work", "Home"] }, "number": { "label": "Number", "type": "string" } } } }Each field key must match a field on the row object that you supply in the HTML binding. In this example,
phoneTypeidentifies the row field,labelsupplies its display label,typedescribes its data type, andenumsupplies the values offered in the condition builder. Thenumberfield is also a string, but has no predefined list of values.When valid row context metadata is available and the feature is enabled, the property rules condition builder displays these fields under Row Context. It uses their declared labels, types, and enum values when you create conditions. The Designer does not infer this field list by scanning the page’s components.
-
In the page’s HTML, update each binding that needs a row-specific property value to pass the current row to
$withEnvbefore reading the constant.For example, change a button’s binding from
disabled="[[ !$constants.isEditable ]]"todisabled="[[ !$withEnv({ row: item.data }).$constants.isEditable ]]"inside the repeated-row template:<oj-bind-for-each data="[[ $variables.phones ]]"> <template data-oj-as="item"> <oj-button disabled="[[ !$withEnv({ row: item.data }).$constants.isEditable ]]"> Edit </oj-button> </template> </oj-bind-for-each>Here,
itemis the template alias anditem.datais the current phone record. Use the row expression available in your template;itemis not a required alias. Preserve any surrounding operators, such as!, so that the binding continues to interpret the property correctly. In this example,isEditableset tofalsedisables the button.You can also use the Variable Picker to insert an eligible extendable, rules-backed page constant in a row-template binding. Select the constant and choose the row-context option. The picker uses the current row variable available in that binding’s scope to generate the
$withEnvexpression. In nested templates, check that the generated expression uses the row source you intend.During rule evaluation, the data passed through
$withEnvis available to the condition as$env.row. -
Open the property rules editor and create a condition using one of the fields under Row Context. See Set Property Values Using Rules.
For the phone example, select Phone Type, choose the equality operator, and select
Work. SetisEditabletofalsewhen the condition is met. The generated condition checks that$env.rowis not null before comparing$env.row.phoneTypewithWork.Row fields are available in rule conditions, but cannot be used in expressions that set the resulting property value. You can combine a row condition with other conditions, such as the user’s role. Review other rules that set the same property, because adding a row-specific rule does not automatically narrow an existing rule that applies to every record.
-
Preview the page with both Work and Home phone records. With the example default and rule, and no other rules overriding the result, the Edit button should be disabled for Work records and enabled for Home records.
If Row Context is missing, check that the JSON metadata is present and valid and that the feature is enabled in your environment. If row conditions appear in the editor but do not affect individual records at runtime, check that the HTML reads the constant through
$withEnvand passes the correct row object. A direct read such as$constants.isEditabledoes not apply row-specific rules.
Row context must be supplied where the individual record is rendered. For example, when a fragment owns a repeated list, evaluate the property inside the fragment’s row template. Passing a property value resolved once at the page-to-fragment boundary does not produce a different value for each row.
For configuring property rules in Express mode, see Set Page and Flow Property Values Using Rules in Extending Oracle Cloud Applications in Visual Builder Studio Express Mode.