# JSMenuItem

## Overview

The `JSMenuItem` scripting wrapper provides functionality for managing menu items in a Servoy application. It supports configuration and interaction through constants, properties, and methods, enabling dynamic customization of menu behavior and appearance. ## Functionality

Constants such as `ENABLED` and `VIEWABLE` control security flags, determining whether menu items are accessible or visible. Properties like `callbackArguments`, `enabled`, `iconStyleClass`, `itemID`, `menuText`, `styleClass`, and `tooltipText` allow precise customization of menu item attributes, including visual styling, text, and state.

The functionality includes methods to manage menu items dynamically. Developers can add new items using methods like `addSubMenuItem`, which supports specifying positions, or retrieve existing items through methods such as `getSubMenuItem` and `getSubMenuItemAt`. Items can also be removed using the `removeSubMenuItem` method.

Security and visibility features allow control over menu item behavior. The `setSecurityFlags` method, combined with constants like `ENABLED` and `VIEWABLE`, provides flexibility to set whether a menu item is visible and interactive. Additional methods, such as `getEnabledWithSecurity` and `getSubMenuItemsWithSecurity`, refine the interaction by considering security constraints.

Properties and additional functionality extend to retrieving extra information, such as through the `getExtraProperty` method, and updating the menu item’s appearance and behavior dynamically. These capabilities make `JSMenuItem` a versatile tool for creating adaptive and secure menu systems in Servoy applications.

[MenuItem](https://docs.servoy.com/reference/servoy-developer/solution-explorer/all-solutions/active-solution/menus/menu-item) section of this documentation

## Constants Summarized

| Type                                                     | Name                  | Summary                                                        |
| -------------------------------------------------------- | --------------------- | -------------------------------------------------------------- |
| [Number](/reference/servoycore/dev-api/js-lib/number.md) | [ENABLED](#enabled)   | Constant representing the enabled flag for menu item security. |
| [Number](/reference/servoycore/dev-api/js-lib/number.md) | [VIEWABLE](#viewable) | Constant representing the viewable flag for menu item seurity. |

## Properties Summarized

| Type                                                       | Name                                    | Summary                                                                     |
| ---------------------------------------------------------- | --------------------------------------- | --------------------------------------------------------------------------- |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)     | [callbackArguments](#callbackarguments) | Set/Get the menu item callback arguments (for components that support this) |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) | [enabled](#enabled)                     | Set/Get the menu item enabled state                                         |
| [String](/reference/servoycore/dev-api/js-lib/string.md)   | [iconStyleClass](#iconstyleclass)       | Set/Get the menu item space separated icon style classes                    |
| [String](/reference/servoycore/dev-api/js-lib/string.md)   | [menuText](#menutext)                   | Set/Get the menu item text                                                  |
| [String](/reference/servoycore/dev-api/js-lib/string.md)   | [name](#name)                           | The menu name (identifier)                                                  |
| [String](/reference/servoycore/dev-api/js-lib/string.md)   | [styleClass](#styleclass)               | Set/Get the menu space separated styleclases                                |
| [String](/reference/servoycore/dev-api/js-lib/string.md)   | [tooltipText](#tooltiptext)             | Set/Get the menu item tooltip text                                          |

## Methods Summarized

| Type                                                            | Name                                                                                                     | Summary                                                                                                                     |
| --------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| [JSMenuItem](/reference/servoycore/dev-api/menus/jsmenuitem.md) | [addMenuItem(id)](#addmenuitem-id)                                                                       | Adds a new menu item, as last item in the list.                                                                             |
| [JSMenuItem](/reference/servoycore/dev-api/menus/jsmenuitem.md) | [addMenuItem(id, index)](#addmenuitem-id-index)                                                          | Adds a new menu item, at a specific position.                                                                               |
| [JSMenuItem](/reference/servoycore/dev-api/menus/jsmenuitem.md) | [findMenuItem(id)](#findmenuitem-id)                                                                     | Gets a menu item by identifier.                                                                                             |
| [Object](/reference/servoycore/dev-api/js-lib/object.md)        | [getCustomProperty(propertyName)](#getcustomproperty-propertyname)                                       | Returns custom property value.                                                                                              |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)      | [getEnabledWithSecurity()](#getenabledwithsecurity)                                                      |                                                                                                                             |
| [Object](/reference/servoycore/dev-api/js-lib/object.md)        | [getExtraProperty(categoryName, propertyName)](#getextraproperty-categoryname-propertyname)              | Returns an extra property value.                                                                                            |
| [JSMenuItem](/reference/servoycore/dev-api/menus/jsmenuitem.md) | [getMenuItem(id)](#getmenuitem-id)                                                                       | Gets a menu item by identifier.                                                                                             |
| [JSMenuItem](/reference/servoycore/dev-api/menus/jsmenuitem.md) | [getMenuItemAt(index)](#getmenuitemat-index)                                                             | Gets a menu item by index (0 based).                                                                                        |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)          | [getMenuItems()](#getmenuitems)                                                                          | Returns all the menus items, either created at design time or at runtime, in the order they will show up in user interface. |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)          | [getMenuItemsWithSecurity()](#getmenuitemswithsecurity)                                                  |                                                                                                                             |
| [JSMenuItem](/reference/servoycore/dev-api/menus/jsmenuitem.md) | [getSelectedItem()](#getselecteditem)                                                                    |                                                                                                                             |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)      | [removeMenuItem(menuItem)](#removemenuitem-menuitem)                                                     | Removes a menu item from children's list, returns true if element was found an removed                                      |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)      | [removeMenuItem(id)](#removemenuitem-id)                                                                 | Removes a menu item with given id, returns true if element was found an removed                                             |
| void                                                            | [selectMenuItem(menuItem)](#selectmenuitem-menuitem)                                                     | Selects a menu item in user interface                                                                                       |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)      | [selectMenuItemById(menuItemId)](#selectmenuitembyid-menuitemid)                                         | Selects a menu item in user interface (by menu id).                                                                         |
| void                                                            | [setCustomProperty(propertyName, value)](#setcustomproperty-propertyname-value)                          | Sets a custom property value.                                                                                               |
| void                                                            | [setExtraProperty(categoryName, propertyName, value)](#setextraproperty-categoryname-propertyname-value) | Sets an extra property value (property must be present in the component spec).                                              |
| void                                                            | [setSecurityFlags(flags)](#setsecurityflags-flags)                                                       | Override the permission data and design data (for enabled flag) and set if a menu item is viewable(visible) and enabled.    |

## Constants Detailed

### ENABLED

Constant representing the enabled flag for menu item security.

**Type**\
[Number](/reference/servoycore/dev-api/js-lib/number.md)

**Sample**

```js
menuItem.setSecurityFlags(JSMenuItem.VIEWABLE|JSMenuItem.ENABLED);
```

### VIEWABLE

Constant representing the viewable flag for menu item seurity.

**Type**\
[Number](/reference/servoycore/dev-api/js-lib/number.md)

**Sample**

```js
menuItem.setSecurityFlags(JSMenuItem.VIEWABLE|JSMenuItem.ENABLED);
```

## Properties Detailed

### callbackArguments

Set/Get the menu item callback arguments (for components that support this)

**Type**\
[Array](/reference/servoycore/dev-api/js-lib/array.md) The callback arguments of the menu item for supported components.

**Sample**

```js
menuItem.callbackArguments = [1];
```

### enabled

Set/Get the menu item enabled state

**Type**\
[Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) The enabled state of the menu item.

**Sample**

```js
menuItem.enabled = false;
```

### iconStyleClass

Set/Get the menu item space separated icon style classes

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md) The space-separated icon style classes of the menu item.

**Sample**

```js
menu.iconStyleClass = 'fas fa-square';
```

### menuText

Set/Get the menu item text

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md) The text of the menu item.

**Sample**

```js
menuItem.menuText = 'Item 1';
```

### name

The menu name (identifier)

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md) the name (identifier) of the menu

### styleClass

Set/Get the menu space separated styleclases

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md) The space-separated style classes applied to the menu.

**Sample**

```js
menu.styleClass = 'myclass';
```

### tooltipText

Set/Get the menu item tooltip text

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md) The tooltip text of the menu item.

**Sample**

```js
menuItem.tooltipText = 'my tooltip';
```

## Methods Detailed

### addMenuItem(id)

Adds a new menu item, as last item in the list.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **id** the menu item identifier

**Returns:** [JSMenuItem](/reference/servoycore/dev-api/menus/jsmenuitem.md) The newly added menu item.

**Sample**

```js
var item = menu.addMenuItem('item1');
```

### addMenuItem(id, index)

Adds a new menu item, at a specific position.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **id** the menu item identifier
* [Number](/reference/servoycore/dev-api/js-lib/number.md) **index** the index position in list (0 based)

**Returns:** [JSMenuItem](/reference/servoycore/dev-api/menus/jsmenuitem.md) The newly added menu item at the specified index.

**Sample**

```js
var mnu = menu.addMenuItem('item1',0);
```

### findMenuItem(id)

Gets a menu item by identifier. Also searches for nested elements. Returns null if not found.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **id** the menu item identifier

**Returns:** [JSMenuItem](/reference/servoycore/dev-api/menus/jsmenuitem.md) The menu item with the specified identifier, including nested items, or null if not found.

**Sample**

```js
var mnu = menu.findMenuItem('item1');
```

### getCustomProperty(propertyName)

Returns custom property value. Custom properties can be defined on each Menu.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **propertyName** The name of the property to retrieve the value for.

**Returns:** [Object](/reference/servoycore/dev-api/js-lib/object.md) The value of the specified custom property, or null if not found.

**Sample**

```js
menuItem.getCustomProperty('myproperty');
```

### getEnabledWithSecurity()

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) Returns whether the menu item is enabled with security constraints applied.

### getExtraProperty(categoryName, propertyName)

Returns an extra property value.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **categoryName** The category name of the extra property.
* [String](/reference/servoycore/dev-api/js-lib/string.md) **propertyName** The name of the property to retrieve the value for.

**Returns:** [Object](/reference/servoycore/dev-api/js-lib/object.md) The value of the specified extra property, or null if not found.

**Sample**

```js
menuItem.getExtraProperty('Sidenav','formName');
```

### getMenuItem(id)

Gets a menu item by identifier. Returns null if not found.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **id** the menu item identifier

**Returns:** [JSMenuItem](/reference/servoycore/dev-api/menus/jsmenuitem.md) The menu item with the specified identifier, or null if not found.

**Sample**

```js
var mnu = menu.getMenuItem('item1');
```

### getMenuItemAt(index)

Gets a menu item by index (0 based). Returns null if not found.

**Parameters**

* [Number](/reference/servoycore/dev-api/js-lib/number.md) **index** the menu item index among its sibblings

**Returns:** [JSMenuItem](/reference/servoycore/dev-api/menus/jsmenuitem.md) The menu item at the specified index, or null if the index is out of bounds.

**Sample**

```js
var mnu = menu.getMenuItemAt(0);
```

### getMenuItems()

Returns all the menus items, either created at design time or at runtime, in the order they will show up in user interface.

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) An array of all menu items in this menu, in the order they appear in the user interface.

**Sample**

```js
var items = menu.getMenuItems();
```

### getMenuItemsWithSecurity()

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) An array of menu items that have the security flag set to "viewable."

### getSelectedItem()

**Returns:** [JSMenuItem](/reference/servoycore/dev-api/menus/jsmenuitem.md) the selectedItem

### removeMenuItem(menuItem)

Removes a menu item from children's list, returns true if element was found an removed

**Parameters**

* [JSMenuItem](/reference/servoycore/dev-api/menus/jsmenuitem.md) **menuItem** the menu item to be removed

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) True if the specified menu item was removed; false otherwise.

**Sample**

```js
var success = menu.removeMenuItem(item);
```

### removeMenuItem(id)

Removes a menu item with given id, returns true if element was found an removed

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **id** the menu item identifier

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) True if a menu item with the specified identifier was removed; false otherwise.

**Sample**

```js
var success = menu.removeMenuItem('item1');
```

### selectMenuItem(menuItem)

Selects a menu item in user interface

**Parameters**

* [JSMenuItem](/reference/servoycore/dev-api/menus/jsmenuitem.md) **menuItem** the menu item to be selected

**Returns:** void

**Sample**

```js
menu.selectMenuItem(item);
```

### selectMenuItemById(menuItemId)

Selects a menu item in user interface (by menu id). Returns whether the item was found and selected.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **menuItemId** the menu item id to be selected

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) True if the specified menu item was selected; false otherwise.

**Sample**

```js
menu.selectMenuItemId('item1');
```

### setCustomProperty(propertyName, value)

Sets a custom property value. Custom properties can be defined on each Menu.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **propertyName** The name of the property to set.
* [Object](/reference/servoycore/dev-api/js-lib/object.md) **value** The value to assign to the specified property.

**Returns:** void

**Sample**

```js
menuItem.setCustomProperty('formName','myform');
```

### setExtraProperty(categoryName, propertyName, value)

Sets an extra property value (property must be present in the component spec).

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **categoryName** The category name of the extra property.
* [String](/reference/servoycore/dev-api/js-lib/string.md) **propertyName** The name of the property to set.
* [Object](/reference/servoycore/dev-api/js-lib/object.md) **value** The value to assign to the specified property.

**Returns:** void

**Sample**

```js
menuItem.setExtraProperty('Sidenav','formName','myform');
```

### setSecurityFlags(flags)

Override the permission data and design data (for enabled flag) and set if a menu item is viewable(visible) and enabled.

**Parameters**

* [Number](/reference/servoycore/dev-api/js-lib/number.md) **flags** either 0 or a combination of JSMenuItem.VIEWABLE and JSMenuItem.ENABLED

**Returns:** void

**Sample**

```js
menuItem.setSecurityFlags(JSMenuItem.VIEWABLE|JSMenuItem.ENABLED);
```

***


---

# 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/dev-api/menus/jsmenuitem.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.
