Scripting enables you to many advanced scenarios. During the edit, before the form is open, you can change the record and form behaviors. In this case, you use Scripting in the Table menu:
Scripting in the table definition menu
You can use these (lifecycle) events:
doo.model
contains all of the table fields and some other predefined properties:
isValid
- when you set the whole model as invalid, it is not possible to save the formisReadOnly
- makes the whole form read-onlyinfoText
- assign a message to this property in case you want to show something in the form headerhideCategory('categoryName')
- it hides the whole category (tab) on the formshowCategory('categoryName')
- and this shows it againThe properties have a format <[Header] (internalName)]>
In case you change the header, the script works without any change. In case you change the internal property of the field, you need to project this into the script.
Every field of the record has these properties/methods:
value
- the current property valuesetValue(value)
- make it easier to assign a value to linked fields, and dates ... See examples for specific data types.originalValue
- the value in the moment the edit startedcurrentlyChanged
- if the value has been changed since the last runisVisible
- if the input is visibleisRequired
- if the input is requiredisEnabled
- if the input is enabledfilterForDropdown
- it is used to filter dropdowns, lookupslabel
- for changing the label/header of the table definitionIn case, you are not sure, how the model object looks like or what the value of a variable is, check the value in the developer console of the browser
console.log(doo.model);
Or you can debug your JavaScript step by step and check values of variables and so on in the developer console of the browser using debugger command in your code (be sure to delete it when done :))
debugger;
You can open the developer console by pressing F12 in Chrome/Edge browser or CTRL+SHIFT+I in Opera browser and similarly in other browsers.
The field "Url" should not be enabled in case the type is not "Digital":
doo.model.url.isEnabled = doo.model.type.value === 'Digital';
The field "Url" should not be visible in case the type is not "Digital":
doo.model.url.isVisible = doo.model.type.value === 'Digital';
Prefill the State field according to the user branch (we added the field branch to the Users table).
doo.model.state.value = doo.currentUser.branch === '550' ? 'New' : 'Active';
The form is not valid in case ...
doo.model.isValid = doo.model.url.value.href.indexOf('http://') === -1;
Filter values for roles. The filtered field State is a Dropdown type
// Admin role can choose from two states, others only one
if (doo.currentUser.roles.indexOf('Admin (system)') != -1) {
doo.model.state.filterForDropdown = ['Active', 'Closed'];
} else {
doo.model.state.filterForDropdown = ['New'];
}
Filtering of linked lookup (this type of filter enables only a few simple conditions!)
doo.model.members.filterForDropdown = "Branch === B01";
doo.model.members.filterForDropdown = "Branch === A01 or Branch === B01";
doo.model.members.filterForDropdown = "Branch contains B01";
// for arrays - multichoice e.g.
doo.model.tasks.filterForDropdown = "state in [New, Canceled]"
The value must be loaded from another table, so you do not enter the exact value, but search criteria. For links to many records, the value can be an array or a single value. For links to one, the value/result should be a single value.
You can find more tips about filters in this chapter
// full text search
doo.model.members.setValue('MyFulltextSearch');
// in case we know the exact value of id
doo.model.members.setValue(['865f8bac-ed8a-4979-972f-3f1706fb1bb1']);
// simplified filter
doo.model.members.setValue({ filter: "surname(in)(Black)" });
if (!doo.model.email.value?.href) {
doo.model.email.value = {
href: doo.currentUser.login,
isMailto: true
};
}