Edit Business Object Fields
You can use the Fields tab of the Business Object editor to modify your business object's fields. You can do this to add functionality to a field, or even to fix errors relating to invalid property values. Fields that contain errors will be underlined in red on the Fields tab.
To edit the properties of a field:
Change a Field's Data Type
You can change a field's data type even after it's been created. This option is useful when you want to create a business object that uses a non-numeric key.
Caution:
Consider the impact of changing an existing field's data type, especially that of a key field. When a field's data type is changed, Visual Builder tries to convert the existing data into the new type, for example, converting a string"10.5"
to its numeric equivalent 10.5
. In the development phase, on a record-by-record basis, if the data cannot be converted to the new type, it will be set to null—other than for a key field. If the key field's data cannot be converted, the entire record will be deleted. If data in an existing deployment schema cannot be converted, you won't be able to stage or publish your app unless you undo the type change, fix the data in the deployment schema to remove any incompatible data, or redeploy choosing the option to create a new schema.
To change the data type of a field:
Set a Default Value for a Field
You can set a default value for a field if the user does not provide a value for it. Based on the field's data type, you might be able to set a static value or an expression as the default.
- Open your business object's Fields editor and select the field you want to modify.
- In the field's Properties pane, select Set to default if value not provided.
- Choose to define a static value or construct an expression:
- To set a static value, select Static Value (selected by default) and enter a value:
-
To set an expression, select Expression from the drop-down list, then construct an expression in the Expression Builder.
Specify operands by typing in the text area or click an operator in the toolbar to add it to your expression. You can also select the Insert arrow for a field in the Business Objects tab or for a function in the Functions tab.
For example, to set the current date as the default hire date for an employee, you might enter
now()
as the expression for the Hire Date field:
Description of the illustration defaultvalue-expression.pngClick OK.
- To set a static value, select Static Value (selected by default) and enter a value:
If you defined a Groovy expression for a field's default value, you can optionally override the default Groovy timeout by clicking the icon in the Properties pane.
Add a Formula to a Field
You can add a formula to calculate the value of a business object's field. You can create a formula to calculate a numerical value, such as a percentage, or you can create a Groovy expression that uses available fields to generate a value. For example, you can concatenate strings stored in local fields (firstName + ‘ ‘ + lastName
) or determine a value based on a comparison or logical expression (qualityLevel != 5
).
You calculate a field's value with a formula in one of two ways: by creating a new formula field or by editing an existing field and adding a formula to calculate its value.
- To create a new formula field:
- To add a formula to an existing field:
Click next to the formula to edit it in the Expression Builder. The expression you supply is evaluated at runtime to return the field’s value each time it is accessed. And when the field is populated, you'll see the value on the Data tab. A field whose value is calculated using a formula is read-only.
When you define a Groovy expression for formula fields, you can optionally override the default Groovy timeout by clicking the icon in the Properties pane.
Add a Field for Aggregating Data
Use aggregation fields in your business objects to aggregate the data of related business objects, for example, to calculate and store the total number of items in an order. You can calculate and store the values of simple operations such as calculating an average or sum, or counting the number of related business objects.
You aggregate a field's data in one of two ways: by creating a new aggregation field or by editing an existing field and adding an aggregation function. For both options, your business object must have a related object with fields that can be aggregated; in other words, a business object with incoming relationships. Let's say you create a field in the Employee business object that refers to the Department object; Employee is the source object and Department is the target object. Department, in this case, is said to have an incoming relationship with Employee.
- To create a new aggregation field:
- To create an aggregation for an existing field:
Click next to the aggregation formula if you want to edit it. When the field is populated, you'll see the aggregated value in the Data tab.
Index a Field
You can index a business object's fields to speed up searches, especially if the field contains thousands of records that are frequently accessed. Indexing a field adds a non-unique index to the field's database column and improves performance when you search for the field's value via REST requests or Groovy code.