Permission sets in Business Central can be defined in AL or created as user-defined permission sets in the tenant. You can export selected permission sets from the client and package them for your extension instead of defining XML by hand.
Important
AL-defined permission sets aren't directly editable in the client. User-defined tenant permission sets remain stored as data and can be edited. System and extension-defined permission sets are different from user-defined tenant permission sets. Learn more in Entitlements and permission sets overview.
To export permission sets from Business Central
- In Business Central, search for Permission Sets, and then choose the relevant link.
- On the Permission Sets page, choose the permissions that you want to export, and then choose Export Permission Sets.
- Save the file to your extension folder.
- If you're replacing a user-defined permission set with an extension-defined set, review its assignments and migration plan before deleting the original. System and extension-defined permission sets can't be deleted here.
You can generate a permission set file which contains permissions to all the files in your extension. This makes it easier to start setting up permissions for your app. You can do this by simply creating an extension with some objects as described below.
To export permission sets using Visual Studio Code
- In Visual Studio Code, open your extension with objects; pages, reports, tables, queries, codeunits, and/or XMLports.
- Open the command palette using the
Ctrl+Shift+Pkeys and select the AL: Generate permission set as XML file containing current extension objects command.Note
Regeneration preserves existing permission values for matching object type and object ID and adds permissions for newly discovered objects. It rewrites the XML file, so review the result and don't assume that arbitrary manual XML changes are preserved.
Now, you have the XML file with default permissions to all your objects.
Example from Visual Studio Code
The following example illustrates the generated .xml file from MyProject which contains a table with objectID 50106 and two object types are generated; <ObjectType>0</ObjectType> is TableData and <ObjectType>1</ObjectType> is Table.
Note
Keep RoleID within 20 characters. The compiler emits a warning when a RoleID exceeds 20 characters; the current XML schema doesn't enforce this limit.
<?xml version="1.0" encoding="utf-8"?>
<PermissionSets>
<PermissionSet RoleID="MyProject" RoleName="MyProject">
<Permission>
<ObjectID>50106</ObjectID>
<ObjectType>0</ObjectType>
<ReadPermission>1</ReadPermission>
<InsertPermission>1</InsertPermission>
<ModifyPermission>1</ModifyPermission>
<DeletePermission>1</DeletePermission>
<ExecutePermission>0</ExecutePermission>
<SecurityFilter />
</Permission>
<Permission>
<ObjectID>50106</ObjectID>
<ObjectType>1</ObjectType>
<ReadPermission>0</ReadPermission>
<InsertPermission>0</InsertPermission>
<ModifyPermission>0</ModifyPermission>
<DeletePermission>0</DeletePermission>
<ExecutePermission>1</ExecutePermission>
<SecurityFilter />
</Permission>
</PermissionSet>
</PermissionSets>
Object type mapping
The generator creates permission entries for the following object types. A table generates both TableData and Table entries, as shown in the XML example.
| Object type | Number |
|---|---|
| TableData | 0 |
| Table | 1 |
| Report | 3 |
| Codeunit | 5 |
| XMLPort | 6 |
| Page | 8 |
| Query | 9 |
The following internal object type values are included for reference. They aren't additional object types emitted by this generator. The schema limits numeric permission XML values to a maximum of 12, so values 14 through 19 aren't valid numeric permission entries.
| Internal object type | Number | Permission XML context |
|---|---|---|
| FieldNumber | 11 | Within the schema's numeric range, but not emitted by this generator. |
| PageExtension | 14 | Not a valid numeric permission entry. |
| TableExtension | 15 | Not a valid numeric permission entry. |
| Enum | 16 | Not a valid numeric permission entry. |
| EnumExtension | 17 | Not a valid numeric permission entry. |
| Profile | 18 | Not a valid numeric permission entry. |
| ProfileExtension | 19 | Not a valid numeric permission entry. |
Related information
Entitlements and permission sets overview
Permissions on database objects
Permissions property
TestPermissions property