How to insert or modify a record when Business Central doesn’t allow direct permissions 

Table of Contents

Every object in Business Central is given various permissions. Assignable Permissions refers to permission sets that may be applied to objects via the user interface (UI), while Non-Assignable Permissions refers to permission sets that cannot be applied via the UI.

Permissions on Object

Each object has one of the four sorts of permissions listed below:

Read R for direct access and r for Indirect access
Write W for direct access and w for Indirect access
Modify M for direct access and m for Indirect access
Delete D for direct access and d for Indirect access

You can only read an object if you have given it read-only rights. You cannot add to or change the data of that object if you don’t have write access.

But what if we only have read permission on the data and want to insert or modify it? Here, I’ll explain how to add or modify a record when Business Central disallows direct permissions.

Let’s take an example of posted sales shipment

Modify Posted Sales Shipment Lines

For instance, we modify some fields of posted sales shipping lines based on certain criteria using the AL code. However we can’t modify the fields using table.insert() or table.modify() directly. Because Business Central does not permit write permissions on the “Sales Shipment Line” table.

We will create a code unit and provide permission to the table in order to allow permissions on it. In this code block, use the onrun() trigger to insert or modify the record.

codeunit 50120 "F3 Shipment Line - Edit"
{
    Permissions = TableData "Sales Shipment Line" = rimd; //Full Indirect access
    TableNo = "Sales Shipment Line";
    trigger OnRun()
    begin
        SalesShipmentLine := Rec;
        SalesShipmentLine.Modify();
        Rec := SalesShipmentLine;
    end;
    var
        SalesShipmentLine: Record "Sales Shipment Line"; }
Related Post