Hi, Readers.
Today I would like to share a mini tip when developing, how to quickly check if the user has the SUPER permissions set.
This is a very simple customization for permission management, such as some key settings pages, only users with Super permission set can access.
I prepared two test users.
Admin: Super permisison set
![](https://yzhums.com/wp-content/uploads/2022/05/image-244-1024x557.png)
YZHU: Only have D365 BUS FULL ACCESS
![](https://yzhums.com/wp-content/uploads/2022/05/image-245-1024x557.png)
Next, as you might know, a more general way is to use table 2000000053 “Access Control”
![](https://yzhums.com/wp-content/uploads/2022/05/image-241-1024x557.png)
If the user can be found in this table with SUPER Role ID, then he has the SUPER permission set.
![](https://yzhums.com/wp-content/uploads/2022/05/image-242-1024x557.png)
So, we can do the following. (If you also deal with different companies, please add another filter for the company here)
![](https://yzhums.com/wp-content/uploads/2022/05/image-243.png)
Source Code:
pageextension 50111 CustomerListExt extends "Customer List"
{
trigger OnOpenPage()
var
AccessControl: Record "Access Control";
begin
AccessControl.Reset();
AccessControl.SetRange("User Security ID", UserSecurityId());
AccessControl.SetRange("Role ID", 'SUPER');
if not AccessControl.IsEmpty then
Message('The user has the SUPER permissions set')
else
Message('The user does not have the SUPER permissions set');
end;
}
There is nothing wrong with this, but please note that this is not the best practise. In fact, Microsoft has prepared a method for us in codeunit 152 “User Permissions”.
procedure IsSuper(UserSecurityId: Guid): Boolean: Checks whether the user has the SUPER permissions set.
![](https://yzhums.com/wp-content/uploads/2022/05/image-240-1024x605.png)
We only need one line of code to check whether the user has Super permissions set. Isn’t it very easy.😁
![](https://yzhums.com/wp-content/uploads/2022/05/image-255.png)
Source Code:
pageextension 50111 CustomerListExt extends "Customer List"
{
trigger OnOpenPage()
var
UserPermissions: Codeunit "User Permissions";
begin
if UserPermissions.IsSuper(UserSecurityId()) then
Message('The user has the SUPER permissions set')
else
Message('The user does not have the SUPER permissions set');
end;
}
Test video:
PS: A very good example can be found in page 9192 “Company Creation Wizard”
![](https://yzhums.com/wp-content/uploads/2022/05/image-246-1024x498.png)
![](https://yzhums.com/wp-content/uploads/2022/05/image-248-1024x447.png)
![](https://yzhums.com/wp-content/uploads/2022/05/image-247-1024x523.png)
END
Hope this will help.
Thanks for reading.
ZHU
コメント