# Method

## Overview

A **Method** is a way of adding custom logic to entities. It can also be used to handle table/entity events. It can be created directly in the entity file from *"methods"* tab or through *"events"* (table, forms, etc.).\
Entity scopes are the foundset scopes to give a foundset extra functionality. They should be used if there are business rules that are based on table/data, really belong to that datasource, so it is just a narrower scope then what named global scope would be.

## File Structure

The code for a Method is stored in a script file in a [Solution](/reference/servoy-developer/project-file-structure/workspace-folder/solution-folder.md) directory -> "datasources" directory -> "table-name" directory. The file has the same name as the table followed by "\_entity", with a `.js` extension. For example, the `orders` table would have the methods file `orders_entity.js`.\
Nesting file path: "solution/datasources/server-name/table-name/table-name\_entity.js"

## Properties Summary

The following properties can be set for Method:

| Property          | Summary                                                 |
| ----------------- | ------------------------------------------------------- |
| [Name](#name)     | The name of the method                                  |
| [Source](#source) | This is the JavaScipt function that defines the method. |

## Properties Details

### Name

The name of the method. It is also the same name as the function.

### Source

This is the JavaScript function that defines the method. Other data providers from this table, related data sources and scope variables can be used.

**Example**

Let's consider *"administration"* table, part of *"exampleData"* database server and a method defined in table entity scope:

```javascript
/**
 * @properties={typeid:24,uuid:"A2F01DCA-0BFB-4045-AF3C-9472064C5D5F"}
 */
function getDefaultAdministration()
{
	if (find()) {
		is_default = 1;

		if (search()) {
			return getRecord(1);
		}
	}
	
	return null;
}
```

The method can be called in solution or forms' scopes, **always related to the same foundset the method is defined for**: "datasources.db.server-name-table-name.getFoundset().EntityMethodName()"

```javascript
	var adminRecord = datasources.db.exampleData.administration.getFoundset().getCurrentAdministration();
```

The method can also be linked to a [table event](/reference/servoycore/object-model/database-server/table.md#events-details) or [form event](/reference/servoycore/object-model/database-server/table/method.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.servoy.com/reference/servoycore/object-model/database-server/table/method.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
