Hi, Readers.
Today I would like to share another mini tip about Business Central, how to quickly check whether the user has write (Insert, Delete, and Modify) permission for the table in AL.
We briefly discussed how to quickly check if the user has the SUPER permissions set via AL (Best practice), Check whether a user has a specific permission set assigned and how to quickly check whether the user has read permission for the table in AL before. This time we will discuss the permissions to write tables in depth again.
As you might know, when a user runs some functions but does not have Insert permission, an error similar to the one below will be prompted.
Sorry, the current permissions prevented the action. (TableData 23 Vendor Insert: Base Application)

Test permission set:

PS: If you do not have the insert and delete permissions, the New and Delete actions in the list page will be grayed out.

And if you do not have Modify permission, you can only open the card page in View mode.

Of course, there is nothing wrong with letting the system throw this error directly, but is it possible to automatically perform other operations when the user does not have write permission? Let me think of a simple example. When the user has write permission for TableData 23 Vendor, open the Vendor Card when creating the related record. If not, open the Customer Card. (Do different processing according to different permissions instead of throwing errors directly)
Yes, it can be done, we can just use Record.WritePermission() Method.
Record.WritePermission() Method: Determines whether a user can write to a table. This method can test for both full write permission and partial write permission that has been granted with a security filter. A write permission consists of Insert, Delete, and Modify permissions.
Here is a simple example from the standard code, codeunit 7499 “Item From Picture”:

Then the above example can be simply done:

PS: Dynamics 365 Business Central: How to open a page in Create/New mode via AL


Test video:
Very simple, give it a try!!!😁
Test code:
pageextension 50115 ItemListExt extends "Item List"
{
actions
{
addafter(CopyItem)
{
action(AddRelatedRecord)
{
ApplicationArea = All;
Caption = 'Add Related Record';
Image = Add;
Promoted = true;
PromotedCategory = Process;
trigger OnAction()
var
Vendor: Record Vendor;
Cust: Record Customer;
begin
if Vendor.WritePermission then begin
Vendor.Init();
Vendor."No." := '';
Vendor.Insert(true);
Page.Run(Page::"Vendor Card", Vendor);
end else begin
Cust.Init();
Cust."No." := '';
Cust.Insert(true);
Page.Run(Page::"Customer Card", Cust);
end;
end;
}
}
}
}END
Hope this will help.
Thanks for reading.
ZHU




コメント