Data structure: default previous value


I want to set the default value of a field with the previous value of that field. For example, I create an element and in the fields of the element there is a table relation, so in the next element I will create the field will be predefined with the same value.
Knows someone if there is a way to do this functionality?

Thanks in advance.


if you need to set a default value according to some logic, you can use table scripting (On model load tab).
For the case you mentioned, you can retrieve the previous record using Tabidoo predefined functions (ideally use function async getData(tableNameOrId, options, application?)). Then you can set the field you want.
Example - consider we have 2 tables - Product (name [text], color [dropdown], category [link to Product Category]) and Product Category (name [text]). We want to set fields Color and Category according to previous Product record:

JS in On model load tab:

// get the last Product record
const result = await doo.table.getData('Product', {limit: 1});
// if exists
if(result?.data?.length > 0) {   
   // set default value for Color field [dropdown value]
   doo.model.<[Color (color)]>.setValue([0].fields.color);  
   // set default value for Category field [link value]
   doo.model.<[Category (category)]>.setValue([0].fields.category?.id);   


1 Like

Hi Jan,

I’ve tried what you explained and it works! I didn’t knew that script option and looks very good.

Thank you very much!