> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MainMenu

> Used to control the main (left-side) menu of SuperOffice CRM. Customizing the main menu means modifying the corresponding trigger.

Used to control the main (left-side) menu of SuperOffice CRM. Customizing the main menu means modifying the corresponding trigger.

## Constructors

### MainMenu()

```crmscript theme={null}
MainMenu
```

Initializes a new instance of the MainMenu class.

## Methods

## addGroup(String,String)

Adds a group to the main menu (navigator) with the given label and image. By default, it appends the item to the bottom of the main menu. Use one of the other addGroup variants to specify the exact position or on-click JavaScript code.

```crmscript theme={null}
Void addGroup(String label, String image)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  The image is specified by the URL to the actual file.
</Note>

**Example:**

```crmscript theme={null}
MainMenu menu = getMainMenu();
menu.addGroup("My label", "http://..../graphics/picture.png");
```

## addGroup(String,String,Integer)

Adds a group to the main menu (navigator) with the given label and image in a specific position. This will shift the index of all subsequent groups. Thus, you should not make assumptions about which slot a group is in.

```crmscript theme={null}
Void addGroup(String label, String image, Integer position)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  The image is specified by the URL to the actual file.
</Note>

**Example:**

```crmscript theme={null}
MainMenu menu = getMainMenu();
menu.addGroup("My label2", "http://..../graphics/picture.png", 3);
```

## addGroup(String,String,Integer,String)

Adds a group to the main menu (navigator) with the given label and image in a specific position. This will shift the index of all subsequent groups. Thus, you should not make assumptions about which slot a group is in.

In addition, you can specify on-click JavaScript code. Use this to create clickable menu groups.

```crmscript theme={null}
Void addGroup(String label, String image, Integer position, String onClick)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  The image is specified by the URL to the actual file.
</Note>

**Example:**

```crmscript theme={null}
MainMenu menu = getMainMenu();
menu.addGroup("My label", "http://..../graphics/picture.png");
menu.addGroup("My label2", "http://..../graphics/picture.png", 3, "window.location='http://www.superoffice.com'");
```

## addItem(String,String)

Adds an item to the SuperOffice main menu (navigator).

```crmscript theme={null}
Void addItem(String label, String url)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
MainMenu menu = getMainMenu();
menu.addItem("List equipment", getProgram(1) + "&action=listExtraTable&extraTable=y_equipment");
menu.addItem("New unit", getProgram(1) + "&action=editExtraTableEntry&extraTable=y_equipment", 1, 1);
```

## addItem(String,String,Integer,Integer)

Adds an item to the SuperOffice main menu (navigator).

```crmscript theme={null}
Void addItem(String label, String url, Integer group, Integer position)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
MainMenu menu = getMainMenu();
menu.addItem("List equipment", getProgram(1) + "&action=listExtraTable&extraTable=y_equipment");
menu.addItem("New unit", getProgram(1) + "&action=editExtraTableEntry&extraTable=y_equipment", 1, 1);
```

## addItem(String,String,Integer,Integer,String,String,String)

Adds an item to the SuperOffice main menu (navigator).

```crmscript theme={null}
Void addItem(String label, String url, Integer group, Integer position, String onClick, String itemId, String target)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

**Example:**

```crmscript theme={null}
MainMenu menu = getMainMenu();
menu.addItem("List equipment", getProgram(1) + "&action=listExtraTable&extraTable=y_equipment");
menu.addItem("New unit", getProgram(1) + "&action=editExtraTableEntry&extraTable=y_equipment", 1, 1);
```

## addItem(String,String,Integer,Integer,String,String,String,String)

Adds an item to the SuperOffice main menu (navigator).

```crmscript theme={null}
Void addItem(String label, String url, Integer group, Integer position, String onClick, String itemId, String target, String iconUrl)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  The image is specified by the URL to the actual file.
</Note>

**Example:**

```crmscript theme={null}
MainMenu menu = getMainMenu();
menu.addItem("List equipment", getProgram(1) + "&action=listExtraTable&extraTable=y_equipment");
menu.addItem("New unit", getProgram(1) + "&action=editExtraTableEntry&extraTable=y_equipment", 1, 1);
```

## clear()

Clears all the contents of the menu.

```crmscript theme={null}
Void clear()
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## deleteGroup(Integer)

Removes the group at the given index (starts at 0) from the main menu.

```crmscript theme={null}
Void deleteGroup(Integer index)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  Verify that you're removing the correct group by checking with getGroupId() what's in that slot first.
</Note>

**Example:**

```crmscript theme={null}
Integer pos = 3;
MainMenu menu = getMainMenu();
if (menu.getGroupId(pos) == "my label") {
  menu.deleteGroup(pos);
}
```

## deleteItem(Integer,Integer)

Removes the item at the given index from the group.

```crmscript theme={null}
Void deleteItem(Integer group, Integer index)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

## getGroupId(Integer)

Returns the label (ID) of a group in the main menu given its position.

```crmscript theme={null}
String getGroupId(Integer group)
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String)

<Note>
  The IDs are unique strings starting at zero.
</Note>

**Example:**

```crmscript theme={null}
MainMenu menu = getMainMenu();
String label = menu.getGroupId(4);
```

## getGroupIndex()

Returns the position of a specific group in the main menu given its label (ID)

```crmscript theme={null}
Integer getGroupIndex(String label)
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The position of a specific group in the main menu.

**Example:**

```crmscript theme={null}
MainMenu menu = getMainMenu();
Integer pos = menu.getGroupIndex("my MITs");
```

## getItemId(Integer,Integer)

Returns the label (ID) of an item in a group given its position.

```crmscript theme={null}
String getItemId(Integer group, Integer pos)
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The label (ID) of an item.

**Example:**

```crmscript theme={null}
MainMenu menu = getMainMenu();
String label = menu.getItemId(4,1);
```

## getItemIndex(Integer,String)

Returns the position of a specific item in the group given its label (ID).

```crmscript theme={null}
Integer getItemIndex(Integer group, String label)
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The position of a specific item.

**Example:**

```crmscript theme={null}
MainMenu menu = getMainMenu();
Integer pos = menu.getItemIndex(2,"secret company");
```

## getNumGroups()

Returns the current number of groups in the main menu.

```crmscript theme={null}
Integer getNumGroups()
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer)

**Example:**

```crmscript theme={null}
MainMenu menu = getMainMenu();
Integer nGroups = menu.getNumGroups();
```

## getNumItems(Integer)

Returns the current number of items in the group.

```crmscript theme={null}
Integer getNumItems(Integer group)
```

**Returns:** [CRMScript.Global.Integer](CRMScript.Global.Integer) - The number of items in the group.

**Example:**

```crmscript theme={null}
MainMenu menu = getMainMenu();
Integer nItems = menu.getNumItems(2);
```


## Related topics

- [Trigger](/en/automation/trigger/reference/CRMScript.Event.Trigger.md)
- [Void](/en/automation/crmscript/reference/CRMScript.Global.Void.md)
- [Namespace CRMScript.Native](/en/automation/crmscript/reference/CRMScript.Native.md)
- [CRMScript Reference](/en/automation/crmscript/reference/index.md)
- [The layout elements on the Main screen](/en/learn/getting-started/main-screen/index.md)
- [Buttons on the top bar](/en/learn/getting-started/main-screen/buttons-in-menu-bar.md)
