doo.model

Accessing and Working with Current Record in Scripts

The doo.model object gives you access to the current record in Scripting within Tabidoo. Whether you're using scripts in form’s lifecycle (on model load, on model change, before model save), or in Workflow Automation, this object is the core way to read and modify field values.

What Is doo.model?

doo.model is a JavaScript object representing the data model of the current record. Each property corresponds to a field in your table.

Properties/Methods

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 form
  • isReadOnly - makes the whole form read-only
  • infoText - assign a message to this property in case you want to show something in the form header
  • hideCategory('categoryName') - it hides the whole category (tab) on the form
  • showCategory('categoryName') - and this shows it again
  • selectCategory('categoryName') - select category (tab)
  • id - serves as an internal record identifier 
  • ver - represents the internal record version

The 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 value
  • setValue(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 started
  • currentlyChanged - if the value has been changed since the last run. Can be used only for onChange script.
  • isVisible - if the input is visible
  • isRequired - if the input is required
  • isEnabled - if the input is enabled
  • filterForDropdown - it is used to filter dropdowns, lookups
  • label - for changing the label/header of the table definition

Scripting Tips

In 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.


Examples

Enable/Disable a field

The field "Url" should not be enabled in case the type is not "Digital":

doo.model.url.isEnabled = doo.model.type.value === 'Digital';

 

Visibility of a field

The field "Url" should not be visible in case the type is not "Digital":

doo.model.url.isVisible = doo.model.type.value === 'Digital';

 

Setting a Dropdown value

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';

 

Form (in)validation

The form is not valid in case ...

doo.model.isValid = doo.model.url.value.href.indexOf('http://') === -1;

 

Dropdown filtering by roles

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'];
}

 

Lookup filtering

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]"

 

Setting the lookup value

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)" });

 

Set email filed to current email

if (!doo.model.email.value?.href) {
    doo.model.email.value = {
        href: doo.currentUser.login,
        isMailto: true
    };
}