Default computed
Default_value_lookup is used for run-time computation of Default values.
For example, when we need to show the current database datetime on a field, SQL server’s getdate() cannot be used directly. This has to be computed at the time of loading page/table.
Computed Default value is implemented similar to a lookup method. A lookup method is specified in Default_value_lookup field. The lookup method should return a scalar value. If the method returns more than one or row or column, row[0], column[0] is used as Default value.
Default_value_lookup should be restricted to use for the following scenarios:
A request table field | If the method specified in Default_value_lookup has a request table, values from other request fields will be used as parameters. |
A computed Default value on a field of a new record (of a response table) | If the method specified in Default_value_lookup has a request table, fields from parent method’s request table will be used as parameters, whereby providing dynamic values based on values of other fields. |
Note: Default_value_lookup is not relevant to for editing existing record.
In Entity Methods (EF.entity_methods) - all methods that are specified as Default_value_method(s) - must be set with has_internal_parameters=true, to prevent using cached data. As an example, current datetime must be computed every time the page is loaded. Without setting has_internal_parameters=true, the current datetime will give previously cached datetime.
Examples in Adventure Works
Entities – AdventureWorks Entities
Url - https://web1.mclsystems.com/AWv32/#/Home
Menu Path – HumanResources -> New Employee ->New Department
Click “Child Department” button in “New Department” grid(New Department = 1).
You will see Child Department page will be shown in bottom of the page.In that page there is a field “Modified Date”, for that field we want to set current date as Default.
Table – ChildDepartment
Field Name – ModifiedDate
Default Value Lookup – CurrentDateTimeLookup
Lookup Data source - select getdate() current_date_time
Steps
a)set Default value lookup “CurrentDateTimeLookup”(it’s already created under system entity, you can create new lookup if not there) to “ModifiedDate” Field and Editor Type should be either “DatePicker” or “DateTimePicker”.
Note: No need to add any codes in page config to set current date for fields in Form.
Output in UI:
a)Click “Add new Record” button in Child Department grid then you will see Current Date will be set for “Modified Date” field.