---
title: "Scripting Extensions"
url: "https://help.tabidoo.cloud/en/article/scripting-extensions"
language: "en"
last_updated: "2023-05-12T09:21:03.392Z"
---

# Scripting Extensions

Scripting Extensions allows you to create custom functions and methods for JavaScript/TypeScript in Tabidoo.

## Intro

Tabidoo includes a lot of features that make scripting easier.   
For example, to retrieve data, just call a generic function

```javascript
const data = await doo.table.getData<IDooApiTableANY>('My table')
```

This built-in functionality makes coding very easy.

Scripting Extensions takes the possibilities even further. It allows you to write **custom functions** that can be **reused** anywhere in Tabidoo. In Workflow Automation, Free Html, etc. No more copy blocks are needed.

## Install

Download the extension "**Scripting Extensions**" into your application. That's it.

## Usage

The "**Custom scripts**" table is the place, where you can extend the Tabidoo standard scripting support.

The input screen contains this fields:

-   Name - just name the record
-   Order - in case you need to setup order, you can use that. Leave empty if not the case.
-   Property name - the name of the property/namespace, which will be appended after standard *doo* keyword. (`doo.**myFunctions**.getNewGuid()`)
-   Interface - name of the interface for this property
-   d.ts - Interface(s) definition
-   Script - TypeScript to define the object. Properties and functions.

The best way would be to go through examples.

## Examples

* * *

### Example 1

We want to define a function, which takes two dates and return a nice text like 1/1/2013 - 2/1/2015

The call supposed to look like

```javascript
doo.myFormatting.getTitle2Days(dateFrom, dateTo, 'en')
```

And the definition:

**Name** My formatting example

**Property name** myFormatting

**Interface** IMyFormatting

**d.ts**

```javascript
interface IMyFormatting {
   getTitle2Days: (dateFrom: Date, dateTo: Date, locale: string) => string;
}
```

**Script**

```javascript
const ret = {
	getTitle2Days: (dateFrom: Date, dateTo: Date, locale: string) => {
 		return `${dateFrom.toLocaleDateString(locale)} - ${dateTo.toLocaleDateString(locale)}`;
	}
};
return ret;
```

* * *

### Example 2

(to show sub-property with async/await)

**We will return rows from our order table, filtered by status = done.**

We will create a sub-property. (We must define the root property as well)

Call should look like

```javascript
const orders = await doo.myLoading.tables.loadFilteredOrders();
```

First - the **root property**.

**Name** My loading example root

**Property name** myLoading

**Interface** IMyLoading

**d.ts**

```javascript
interface IMyLoading{
   tables: IMyLoadingTables;
}

interface IMyLoadingTables {
	loadFilteredOrders: () => IDooApiTableOrders[];
}
```

**Script**

Leave it empty. Now, we just defined type of *doo.**myLoading*** property.

And now the ***doo.myLoading.tables*** functionality. (In the previous step we defined myLoading property)

**Name** My loading example table

**Property name** myLoading.tables

**Interface** IMyLoadingTables

**d.ts**

Just leave empty. We already defined the interface in the previous record.

**Script**

```javascript
const loadFilteredOrders = async () => {
const result = await doo.table.getData<IDooApiTableANY>('Orders', { filter: 'status(eq)done' });
    return result.data;
};
var ret = {
    loadFilteredOrders: loadFilteredOrders
}
return ret;
```

## Tips

> ### Reuse
> 
> In case you want to reuse your code in more applications (have your own library), you can create an application with these definitions and distribute them vie Templates.
