Work with Polymorphic Objects in a Layout

When you are adding fields to a layout, the Fields palette might include polymorphic objects containing fields you can select. Polymorphic objects are defined by the service that your extension uses, and define a set of fields rather than a single field. A polymorphic object can display different field subsets based on a pre-defined discriminator sub-type that is evaluated at runtime. The polymorphic object might have several sub-types for the discriminator field, each defining a different set of fields.

In the image below, ExpenseDff is a polymorphic object, and __FLEX_Context is the discriminator field.



An @all field is automatically added when you add a polymorphic object to a layout, but you can also explicitly add fields to the center pane. When the center pane contains the @all field, all the fields, as determined by the discriminator, will be displayed in the layout. You can control the order that fields are displayed in the polymorphic object by explicitly adding fields to the object in the center pane.

In the example above, the discriminator has a sub-type Lunch that determines the fields that will be displayed (ExpenseId, expenseLine1, lunch1, lunch2, lunch3). All of those fields will be displayed when the Lunch sub-type is applied at runtime because the polymorphic object in the center pane includes the @all field. If you remove the @all field from the center pane without explicitly adding any fields, no fields will be displayed in the layout.

By explicitly positioning some of the fields (lunch2, ExpenseId), as in the image below, you can control the display order of the fields.



The fields will appear in the following order when the Lunch sub-type is applied to the discriminator:

  1. lunch2 (added and positioned explicitly)
  2. ExpenseId (added and positioned explicitly)
  3. expenseLine1 (added using @all)
  4. lunch1 (added using @all)
  5. lunch3 (added using @all)

If the @all field is removed, only the fields added explicitly (lunch2, ExpenseId) will be displayed when the Lunch sub-type is applied.

If the wifi field was added explicitly to the object, it wouldn't be displayed when the Lunch sub-type is applied to the discriminator.

To add a polymorphic object to your layout:

  1. In the Rule Sets editor, open the layout you want to work on.
  2. Select the polymorphic object in the Fields palette, or drag it from the palette into the list in the center pane.

    The Fields palette lists all the fields and objects you can add to your layout, including polymorphic objects. Polymorphic objects in the palette have a special object icon ( polymorphic object field icon ). You can expand the object node in the palette to see the sub-fields that could potentially be displayed if you added the object to the layout.

    If you want to see which fields you can add to the center pane, for a specific sub-type:

    1. Expand the object node in the palette.
    2. Click Modify and select a sub-type from the list. You can also broaden the filter by selecting more than one sub-type.
    3. Click Filter to filter the fields displayed under the object node.


    In the image below, the sub-fields of the polymorphic object ExpenseDff are filtered by the Meal sub-type. Instead of listing all the object's sub-fields, only the sub-fields defined by the Meal sub-type (drink, ExpenseId, expenseLine1) are listed under the object node. These are the fields that will be displayed when the @all field is added to the center pane and the Meal sub-type is applied.



    By seeing the fields defined for each sub-type, you can decide which fields you might want to add to the center pane, if any.

  3. Arrange the order that fields are displayed in the component by dragging fields into position in the center pane.
    You can control the order that a polymorphic object's fields are displayed by adding them explicitly and positioning them where you want.