Create a Rule in a Rule Set

Once you've opened the rule set for the component you want to configure, you can start adding rules to the display logic. You'll see that the display logic will already have a default rule, and you'll add your rules above it. The order in which they appear in the display logic tree is important because at runtime the rules are evaluated from top to bottom. The first rule where all the conditions are met is the one that's used, and the associated layout is applied to the component. No other rules are tested. Keep this in mind as you’re working on the display logic rules.

To configure rules in the display logic:

  1. Open the rule set you want to configure.
  2. Under Display Logic, click Add Rule and give it a name, preferably something meaningful. For example, to create a rule that displays only when the user is a sales manager, you might call the rule isSalesManager.

    The rule set for a dynamic component always contains a default rule that is set by the Layout in the dependency. You can't change this rule, but you can copy it to use it as the basis for your own rules, or you can create a rule from scratch.



    If you want to also create a copy of the layout to use as a starting point, make sure that check box is selected in the Duplicate Rule dialog box.

  3. In your new rule, click Click to add condition, then select an Attribute and Operator from the dropdown lists, and select or enter a Value. Click Done.

    The Attributes dropdown list contains the fields and variables that you can use, and the Operators list contains the operators (for example, '=' and '<=') that are valid for the attribute you select. You can set the Value by typing in the field or selecting a value in the dropdown list. If a list of valid values for the attribute can be determined from the data source, the values will be displayed in the Value dropdown list. For example, if the service definition contains an attribute (Status) that can have three valid values ('Not Started', 'In Progress', and 'Completed'), the dropdown list would display these values.

    There are several context objects in the Attributes list that you can use when building rules. In addition to the $fields context, there are variables in other built-in contexts that provide a way to access various pieces of information when building conditions. For example, you can check the size of the device accessing your app, or information about the user using the app such as their role or email. Context variables include:

    • $fields variables determined by the fields available in the Layout. For example, the $fields.firstName.value lets you access the value of the First Name field in your data source. Look for these variables under the Fields group in the condition builder.

      Note:

      For each field, regardless of type, you can choose $numberValue (for example, $fields.ConflictId.numberValue()) or $value ($fields.ConflictId.value()). You should use $numberValue when you know the field's value should contain a number. For example, if the ConflictId field's type is a string and you choose $numberValue, the field's value will be converted to a number, if possible. If the value can't be converted, the $numberValue will be NaN (Not a Number).

      The only limitation is that $numberValue is limited by the maximum precision allowed by the Number type in Javascript.

    • $responsive variables determined by the screen size of the device the app is currently displayed on. For example, the responsive.mdUp variable's value is True if the current user is using a device where the screen width is 768 pixels or more, such as a tablet. Look for these variables under the Responsive group in the condition builder.
    • $user variables determined by the current user. For example, the user.isAuthenticated variable's value is True if the current user is an authenticated user. You can use the user.roles variable to check the role of the user using the app. Look for these variables under the User group in the condition builder.

      Note:

      When using user.roles, the Value drop-down lists the available Oracle Applications Cloud job and abstract roles. (The drop-down will not list any duty roles. If you want to specify a duty role, you can manually type the duty role name in the Value field.)

    Note:

    A rule condition can also specify a discriminator sub-type value when the attribute is a polymorphic object. When you open the layout associated with a rule which specifies a sub-type, the object's sub-fields in the Fields palette will be filtered using that sub-type. For example, if a condition requires the Meal sub-type, when you open the rule's layout, the object's sub-fields will be filtered for that sub-type.

    If you want to edit or remove the filter, click Modify under the object in the Fields palette. To re-apply the filter using the same sub-type, click Reset according to Display Logic rule. For more details, see Work with Polymorphic Objects in a Layout.

    You can add more conditions and group conditions if you want to use more attributes to make the rule more precise. For example, you may want to use a layout that displays an extra column if the user has the manager role AND is on a device that has a medium-sized screen. You would then create a rule with two conditions, and select Match All to require that both conditions are true.



    If you select Match Any, then the rule will be evaluated as true if any of the conditions in the rule are true.

  4. In the return field, select the layout you want to apply when the rule is true.

    If you created a copy of a layout when you created the rule, it is selected by default in the return field. You can use the same layout with multiple rules.

  5. Click Add Rule to add another rule, and then build its conditions.
  6. Use the Move Up and Move Down buttons to make sure you have the rules in the order you want them evaluated.


    Remember, the order and precision of your rules is important. The rules are evaluated from the top down, so the first rule evaluated as true will determine the layout that is used. When configuring the display logic, it's not a problem if there are rules that will never be used or evaluated.

Preview Rule Set Layouts

To preview how different layouts will look when applied to your page, use the Layout Preview in the page's Properties pane. Layout Preview forces the Page Designer to use the layout you select and ignore the rules in the rule set. For example, if you created a layout that only managers can see, you won't see it in the Page Designer if you're not logged in as a manager. You use Layout Preview in the Properties pane to override the display logic and render the page using the layout you select.

To preview a rule set layout in the Page Designer:

  1. Open the page in the Page Designer and select the dynamic table or form you want to preview.

    In the component's Properties pane, the Layout Preview dropdown list displays all the layouts that have been defined in the component's rule set.

  2. Select a layout in the Layout Preview dropdown list:


    In this image, the managerLayout layout is selected in Layout Preview, and the dynamic form is rendered using the layout. To open the layout in the editor, click Configure Layout.

  3. Click Reset to return to the default "Resolved by display logic" option.

Create a Rule Based on User and Device

When you're creating rules, you build conditions using the dropdown lists to select an Attribute, Operator and Value. In addition to fields retrieved from the Oracle Cloud Application, the Attributes dropdown list includes some built-in variables storing details about the current user and the device they're using. You can use them, for example, to create a condition that is true only when authenticated users are viewing the page on a tablet-sized screen or larger:



You can select built-in variables that are determined by your extension's context (for example, user.email). Two kinds of built-in extension context ($context) variables are available:

  • user variables are determined by the current user. For example, the user.isAuthenticated variable's value is True if the current user is an authenticated user.

  • responsive variables are determined by the screen size of the device your application is currently displayed on. For example, the responsive.mdUp variable's value is True if the current user is using a device where the screen width is 768 pixels or more, such as a tablet.

If you click Display as codeyou can open an editor to see and edit the expression for the rule:



For the rule above, you'd see the following expression:
$user.isAuthenticated === true && $responsive.mdUp === true ? 'managerLayout_small' : null

Note:

Depending on your Oracle Cloud Application, when using $context.user.roles in a condition or display properties, the list of values might contain the app's pre-defined roles (for example, $context.user.roles.manager). If the attributes list displays roles as a property, in your rule you would specify the value as true or false. If the roles are not listed, then type in the role name manually.