import { Callout } from "zudoku/ui/Callout";

# Group-based Printer Selection

<Callout type="info" title="Info">
This function is available from version <b>18.12</b> of the 365 business Print Agent.<br/>
Please make sure that you are using the latest version.
</Callout>

**Group-based printer selection** allows you to assign printers to users based on their [security groups](https://learn.microsoft.com/en-us/dynamics365/business-central/ui-define-granular-permissions). This enables you to manage printers for groups of users instead of configuring each user individually.

## What is Group-based Printer Selection?

Group-based printer selection extends the standard printer selection by adding a layer where printers can be assigned not only to individual users or reports, but also to **user groups**.

- **User-specific assignments** take precedence over group assignments.
- **Report-specific assignments** (for a specific report) take precedence over general assignments (without a report).
- Group assignments apply to **all members** of the assigned security group.

## How does Group-based Printer Selection work?

The group-based assignment is handled by codeunit `bdev.PrA Group Printer Sel.` (5523825), which is automatically invoked during the print process. It checks:

1. Whether group-level assignments are applicable (no explicit user-report printer exists)
2. The security groups the current user is a member of
3. The printer assignments for those groups (by report ID, then generally)

The logic is as follows:

1. Check if the user is a member of any security group.
2. Search for a printer assignment for the group with the current report ID.
3. If no report-specific printer is found, check for general group printer assignments (Report ID = 0).
4. The found printer name is used if it exists.

## Prerequisites

- Microsoft Dynamics 365 Business Central (BC22 or later)
- 365 business Print Agent version 18.12 or later
- Users must be members of at least one security group

## Usage

Group-based printer selection is **automatically** applied during print operations. No manual configuration on the printer selection page is required.

Assignment is done via table **"bdev.PrA Group Printer Sel."**, which is maintained through AL development or import tools.

### Example: Assign a printer to a security group

| Group Code   | Report ID | Printer Name     |
|--------------|-----------|------------------|
| SALES-DEPT   | 100       | HP-LaserJet-100  |
| SALES-DEPT   | 0         | HP-LaserJet-All  |

- Users in the `SALES-DEPT` security group will use `HP-LaserJet-100` when printing report 100.
- For all other reports, they will use `HP-LaserJet-All`.

## Background

The feature uses Business Central's standard event subscriber logic:

```al
[EventSubscriber(ObjectType::Codeunit, Codeunit::ReportManagement, "OnAfterGetPrinterName", '', true, true)]
local procedure SetPrinterNameForGroupPrinterSelectionOnAfterGetPrinterName(...)
```

The event subscriber is called after the standard printer selection and replaces the printer name if a group assignment exists.

### Technical Details

- **Object ID**: Codeunit 5523825 "bdev.PrA Group Printer Sel."
- **Event Subscriber**: `ReportManagement.OnAfterGetPrinterName`
- **Table**: `bdev.PrA Group Printer Sel.` (5523825)
- **Security**: The codeunit checks Read permissions for the group table.

## See also

- [Printer Access Permission](printer-access-permission.mdx)
- [Printer Selection (Microsoft Learn)](https://learn.microsoft.com/en-us/dynamics365/business-central/ui-define-granular-permissions)