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

# Customize the Context Menu

> Tailor the right-click context menu in Nextedy RISKSHEET to add custom actions, control menu visibility for hierarchical levels, and extend functionality through JavaScript extensibility points.

export const LastReviewed = ({date}) => {
  if (!date) return null;
  const formatted = new Date(`${date}T00:00:00Z`).toLocaleDateString("en-US", {
    year: "numeric",
    month: "long",
    day: "numeric",
    timeZone: "UTC"
  });
  return <p className="mt-10 text-sm text-gray-400 dark:text-zinc-500 not-prose">
      Last reviewed on {formatted}
    </p>;
};

## Default Context Menu Actions

When you right-click a cell in the Risksheet grid, the context menu displays built-in actions depending on the cell context and grid state:

| Action                  | When Available                              | Description                                                                                                                                                              |
| ----------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Open Row Item**       | Always                                      | Opens the current row's work item in Polarion's item editor                                                                                                              |
| **Open \[Column] Item** | Cell contains a valid item link             | Opens the linked work item for that column (the label includes the column name, e.g. **Open Item/Func Item …**)                                                          |
| **Open Task Item**      | Cell contains a task link                   | Opens the task work item; label uses `dataTypes.task.name` if configured                                                                                                 |
| **New \[Level] Item**   | Editable grid, `showInMenu: true`           | Creates a new work item at the selected hierarchy level (e.g. **New Item**, **New Failure mode**, **New Cause**)                                                         |
| **Overwrite Row Item**  | Item has `systemReferenceType: "reference"` | Converts a referenced item to overwrite mode for local editing                                                                                                           |
| **Remove Row Item**     | Non-read-only grid                          | Removes the selected row from the grid                                                                                                                                   |
| **Freeze Pane**         | Always                                      | Freezes columns to the left of the current column                                                                                                                        |
| **Unfreeze Pane**       | Columns are frozen (`frozenColumns > 0`)    | Removes column freezing                                                                                                                                                  |
| **Copy link to row**    | Always                                      | Copies a direct link to the current row to the clipboard                                                                                                                 |
| **Debug**               | Developer/debug mode active                 | Outputs cell diagnostic info to the browser console. Debug mode is a developer/runtime mode and is **not** enabled through the sheet configuration (see the note below). |

<Frame>
  <img src="https://mintcdn.com/none-17b4493f/yWl5nA2D0IzEnZC1/risksheet/diagrams/guides/customization/context-menu/diagram-1.svg?fit=max&auto=format&n=yWl5nA2D0IzEnZC1&q=85&s=f63269eb65d95848993fd9032a16cc81" alt="diagram" style={{ maxWidth: "480px", width: "100%" }} width="480" height="340" data-path="risksheet/diagrams/guides/customization/context-menu/diagram-1.svg" />
</Frame>

## Register Custom Context Menu Actions

Risksheet exposes an extensibility point through `window.risksheet.customContextMenuActions` that allows top panel scripts to register additional menu items. The canonical registration pattern uses **string function names** (resolved against the global `window` object at runtime) for both the enable and execute hooks.

### Step 1 -- Define Action Functions

Create JavaScript functions on the global `window` object. Each custom action needs an enable function (controls when the item is active) and an execute function (runs when clicked):

```javascript theme={null}
// Enable function: receives the current row item, returns boolean
window.isReportEnabled = function(item) {
  return item && item.type === "risk";
};

// Execute function: receives the current row item
window.generateRiskReport = function(item) {
  alert("Generating report for: " + item.title);
};

window.isCopyEnabled = function(item) {
  return item !== null;
};

window.copyItemToClipboard = function(item) {
  navigator.clipboard.writeText(item.id + ": " + item.title);
};
```

### Step 2 -- Register the Actions

Add your custom actions to the `customContextMenuActions` array. Always reference the enable and execute hooks **by function name as a string** — Risksheet looks the names up on `window` when the menu opens:

```javascript theme={null}
window.risksheet = window.risksheet || {};
window.risksheet.customContextMenuActions = [
  {
    label: "Generate Risk Report",
    enableFn: "isReportEnabled",
    executeFn: "generateRiskReport"
  },
  {
    label: "Copy to Clipboard",
    enableFn: "isCopyEnabled",
    executeFn: "copyItemToClipboard"
  }
];
```

Each custom action object requires three properties:

| Property    | Type     | Description                                                          |
| ----------- | -------- | -------------------------------------------------------------------- |
| `label`     | `string` | Text displayed in the context menu                                   |
| `enableFn`  | `string` | Name of a `window` function that returns `true` to enable the action |
| `executeFn` | `string` | Name of a `window` function that runs when the action is clicked     |

<Warning title="Use string function names — not inline functions">
  `enableFn` and `executeFn` must be **strings naming a function on `window`**. Assigning inline function expressions (for example `enableFn: function(item) { ... }`) is not the supported registration form and the menu action will not appear. Define each function on `window` first, then reference it by name.
</Warning>

### Step 3 -- Load the Script

Place the script in your top panel configuration (`risksheetTopPanel.vm`) so it loads when Risksheet initializes:

```velocity theme={null}
<script>
  // Define functions on window, then register actions
  window.isReportEnabled = function(item) { return item && item.type === "risk"; };
  window.generateRiskReport = function(item) { /* ... */ };

  window.risksheet = window.risksheet || {};
  window.risksheet.customContextMenuActions = [
    { label: "Generate Risk Report",
      enableFn: "isReportEnabled",
      executeFn: "generateRiskReport" }
  ];
</script>
```

<Warning title="Functions must be on the global window object">
  Because `enableFn` and `executeFn` are resolved by name, functions defined inside closures, IIFEs, or module scopes will not be found at runtime and the menu action will silently fail. Always attach them to `window`.
</Warning>

## Control New Item Menu Options

The "New \[Level] Item" menu options are generated dynamically from the `levels` configuration in the sheet configuration. Use `showInMenu` to control which levels appear:

```yaml theme={null}
levels:
  - name: Failure Mode
    controlColumn: systemItemId
    zoomColumn: systemItemId
    showInMenu: true
  - name: Cause
    controlColumn: cause
    zoomColumn: cause
    showInMenu: true
  - name: Internal Reference
    controlColumn: reference
    zoomColumn: reference
    showInMenu: false
```

Setting `showInMenu` to `false` hides that level from the context menu while keeping it functional in the grid hierarchy. This is useful for levels populated automatically or through imports.

## Customize Task Menu Labels

The "Open Task Item" menu label dynamically reflects the configured task type name. Set `dataTypes.task.name` in the sheet configuration:

```yaml theme={null}
dataTypes:
  task:
    name: Mitigation Action
    type: mitigationAction
    role: mitigates
```

With this configuration, the context menu displays "Open Mitigation Action" instead of the default "Open Task".

## Overwrite Row Item

The "Overwrite Row Item" action converts a referenced item to overwrite mode, enabling local modifications to be saved back to the source. This action appears only when the selected item has `systemReferenceType` set to `reference`.

<Note title="Use Debug mode to inspect item state">
  When **Debug** is available in the context menu, it logs the ghost status, column ID, cell value, full item object, and comparison manager state to the browser console — invaluable when diagnosing why an overwrite action is unavailable.

  Debug mode is a developer/runtime mode and is **not** enabled through the sheet configuration. Setting `debug: true` in the `global` section has no effect (the key is silently ignored), and there is no `appConfig.debug` setting that turns it on.
</Note>

<Info title="Document workflow transitions">
  Triggering Polarion document workflow transitions (for example, changing document status from within Risksheet) is not provided as a built-in menu item. Use the `customContextMenuActions` extensibility point to call the appropriate Polarion endpoint from your custom function.
</Info>

## Verify Your Changes

After configuring custom context menu actions:

1. Reload the Risksheet page to load your top panel script changes.
2. Right-click on a grid cell — you should now see your custom menu items alongside the built-in actions.
3. Verify that the `enableFn` condition correctly enables and disables the action based on the selected item.
4. Check the browser console for errors if a custom action does not appear (a common cause is a function defined inside a closure rather than on `window`).

## See Also

* [Customize the Top Panel](/risksheet/guides/customization/top-panel) — add scripts and custom fields to the top panel area
* [Configure Remove/Delete Actions](/risksheet/guides/risk-management/remove-delete-risk) — control how items are removed from the grid
* [Understanding the Interface](/risksheet/getting-started/understanding-interface) — overview of Risksheet UI components
* [Create Custom Renderers](/risksheet/guides/customization/custom-renderers) — extend cell rendering with custom display logic

<LastReviewed date="2026-06-24" />
