Resolve Expressions in Page Properties Based on Fragment Data

(For advanced users) When a fragment accepts input parameters for page-level properties such as Title or Subtitle, these values can come from expressions that are evaluated within the scope of the page. For example, an Edit page's title could be Edit Employee John Doe, where John Doe is a value generated from fetched data to resolve the expression 'Edit Employee: ' + $variables.objectValue.firstName + ' ' + $variables.objectValue.lastName.

The firstName and lastName values are fetched by the fragment when the page loads and are exposed to the page through the $variables.objectValue variable, allowing the page to resolve the expression.

Here's how this works in an Edit page with a dynamic form in a fragment: Say the page's title—displayed as a heading component—is bound to a variable within the fragment. Because the title expression relies on data fetched by the fragment, the page must do two things: pass the resolved expression to the fragment as an input parameter as well as provide a list of fields required to resolve that expression. To do this, the fragment variable is designated as a special input type, allowing container pages to provide the information the fragment needs to request when making a REST endpoint call to fetch data. This information specifically includes:
  • value: The value that the fragment should pick as the title's value to show in a component in HTML markup, for example, Edit Employee John Doe.
  • referencedFields: List of fields used to compute the value expression, for example, ["objectValue.firstName", "objectValue.lastName"].

The fragment combines the referencedFields with other fields from the edit page's dynamic form and passes it to a Call REST action to retrieve the data that the page needs to render correctly. Once the data is fetched, it is stored in a data variable (objectValue, for example) and exported to the page as a writeback input parameter, allowing the page to resolve the value expression.

To make this data exchange work, your fragment variables must be assigned the correct binding type subtype to provide information that VB Studio requires to generate suitable metadata and expressions:

  1. Create a variable to store the data returned by a REST endpoint call, ensuring it references a separate variable or constant that specifies the endpoint’s data structure.
    1. In the fragment's Variables editor, create a variable or constant (objectValue, for example) with its Type set as Object and enable it as an input parameter.
    2. In the Design Time tab, select the Subtype as Business Object Value.
    3. In the Endpoint Variable list, select the fragment-level variable or constant (endpoint, for example) that describes the data structure of the REST endpoint from which data is fetched. (The variable or constant with Subtype as Endpoint must already be set up.)
  2. Create a variable or constant that infers an internal structure with an expression referencing the value from a data variable (with Subtype as businessObjectValue) and a list of referencedFields used in that expression.
    1. In the fragment's Variables editor, create a variable or constant (title, for example) with its Type set as Object and enable it as an input parameter.
    2. In the Design Time tab, select the Subtype as Business Object Value Reference.
    3. Optional: In the Placeholder field, specify a hint text for the variable; for example, Enter page title.