# JSMethod

## Overview

The `JSMethod` scripting wrapper provides tools for managing and interacting with solution model script methods in Servoy. It includes properties and methods that allow customization of script behavior, source code, and visibility in the client interface. ## Functionality

The `code` property stores the full source code of a method, including its documentation and declaration. It supports dynamic updates, enabling modifications to method functionality at runtime. The `showInMenu` property determines whether a method is displayed in the "Methods" menu of the Servoy Client, allowing developers to manage method visibility.

Several methods enhance interaction with script methods. `getArguments` retrieves an array of arguments set for a method, which is useful for analyzing and reconfiguring parameterized actions. `getName` provides the name of the method, while `getScopeName` returns the associated scope, useful for organizing global or local method interactions. `getUUID` returns the universally unique identifier of the method object, aiding in identifying and managing methods programmatically.

These capabilities make JSMethod a versatile component for customizing and extending script-based behavior in Servoy applications.

For details read the[Method](https://docs.servoy.com/reference/servoycore/object-model/database-server/table/method) section of this documentation

## Properties Summarized

| Type                                                                           | Name                      | Summary                                                                              |
| ------------------------------------------------------------------------------ | ------------------------- | ------------------------------------------------------------------------------------ |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [code](#code)             | The full source code of this method (including doc and function declaration).        |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [showInMenu](#showinmenu) | Flag that tells if the method appears or not in the "Methods" menu of Servoy Client. |

## Methods Summarized

| Type                                                                          | Name                            | Summary                                                                                                   |
| ----------------------------------------------------------------------------- | ------------------------------- | --------------------------------------------------------------------------------------------------------- |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)    | [getArguments()](#getarguments) | Gets the argument array for this method if that is set for the specific action this method is taken from. |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)  | [getName()](#getname)           | The name of the method.                                                                                   |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)  | [getScopeName()](#getscopename) | Get scope name                                                                                            |
| [UUID](https://docs.servoy.com/reference/servoycore/dev-api/application/uuid) | [getUUID()](#getuuid)           | Returns the UUID of the method object                                                                     |

## Properties Detailed

### code

The full source code of this method (including doc and function declaration).

**Type**\
[String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) The declaration code of the script method.

**Sample**

```js
var method = form.newMethod('function original() { application.output("Original function."); }');
application.output('original method name: ' + method.getName());
application.output('original method code: ' + method.code);
method.code = 'function changed() { application.output("This is another function."); }';
method.showInMenu = false;
var button = form.newButton('Click me!', 10, 10, 100, 30, method);
```

### showInMenu

Flag that tells if the method appears or not in the "Methods" menu of Servoy Client.

**Type**\
[Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) True if the method is shown in the menu; false otherwise.

**Sample**

```js
var method = form.newMethod('function original() { application.output("Original function."); }');
application.output('original method name: ' + method.getName());
application.output('original method code: ' + method.code);
method.code = 'function changed() { application.output("This is another function."); }';
method.showInMenu = false;
var button = form.newButton('Click me!', 10, 10, 100, 30, method);
```

## Methods Detailed

### getArguments()

Gets the argument array for this method if that is set for the specific action this method is taken from.\
Will return null by default. This is only for reading, you can't alter the arguments through this array,\
for that you need to create a new object through solutionModel.wrapMethodWithArguments(..) and assign it again.

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) Array of the arguments, null if not specified.

**Sample**

```js
var frm = solutionModel.getForm("myForm");
var button = frm.getButton("button");
// get the arguments from the button.
// NOTE: string arguments will be returned with quotes (comp.onAction.getArguments()[0] == '\'foo\' evals to true)
var arguments = button.onAction.getArguments();
if (arguments && arguments.length > 1 && arguments[1] == 10) {
	// change the value and assign it back to the onAction.
	arguments[1] = 50;
	button.onAction = solutionModel.wrapMethodWithArguments(button.onAction,arguments);
}
```

### getName()

The name of the method.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) A String holding the name of this method.

**Sample**

```js
var method = form.newMethod('function original() { application.output("Original function."); }');
application.output('original method name: ' + method.getName());
application.output('original method code: ' + method.code);
method.code = 'function changed() { application.output("This is another function."); }';
method.showInMenu = false;
var button = form.newButton('Click me!', 10, 10, 100, 30, method);
```

### getScopeName()

Get scope name

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) The scope name in which the method is defined.

**Sample**

```js
var methods = solutionModel.getGlobalMethods();
for (var x in methods)
	application.output(methods[x].getName() + ' is defined in scope ' + methods[x].getScopeName());
```

### getUUID()

Returns the UUID of the method object

**Returns:** [UUID](https://docs.servoy.com/reference/servoycore/dev-api/application/uuid) The UUID of the method object.

**Sample**

```js
var method = form.newMethod('function original() { application.output("Original function."); }');
application.output(method.getUUID().toString());
```

***
