web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Error with Install codeunit BC Saas - 'The record in table User Group Permission Set already exists. Identification fields and values:

(0) ShareShare
ReportReport
Posted on by 15

Hi,

I wanted to assign permission set to user group during installing the extension in BC and below is the code. The installation failed with error 

'Could not install the extension 'XXX on tenant 'default' and company '' due to the following error: 'The record in table User Group Permission Set already exists. Identification fields and values: User Group Code='D365 ACCOUNTANTS',Permission Set='TRANS. ACCESS',Scope='System',App ID='{3AD0200B-B072-4763-9F04-7880752C6086}''

Any idea how to fix this error?
CODE:   
 
codeunit 60007 "Install Codeunit - A"
{
    subtype = Install;

    trigger OnInstallAppPerCompany()
    var
        myAppInfo: ModuleInfo;

    begin

        AddPermissionSetToUserGroup('Base Trans', UserGroupLabel1);
        AddPermissionSetToUserGroup('Trans. Access', UserGroupLabel2);

    end;

    procedure AddPermissionSetToUserGroup(PermissionSetId: Code[20]; UserGroup: Text)
    var
        PermissionSet: Record "Permission Set";
        UserGroupPermissionSet: record "User Group Permission Set";
        UserGroupPermissionSet2: record "User Group Permission Set";
        UserGroupCode: Code[20];
    begin
        if not PermissionSet.Get(PermissionSetID) then
            exit;

        UserGroupCode := CopyStr(UserGroup, 1, MaxStrLen(UserGroupPermissionSet."User Group Code"));
        clear(UserGroupPermissionSet);

        if UserGroupPermissionSet.Get(UserGroupCode, PermissionSetId) then
            exit;

        UserGroupPermissionSet.init;
        UserGroupPermissionSet."Role ID" := PermissionSetId;
        UserGroupPermissionSet."User Group Code" := UserGroupCode;
        UserGroupPermissionSet.Insert();
    end;


    var
        UserGroupLabel1: Label 'D365 FULL ACCESS', Locked = true;
        UserGroupLabel2: Label 'D365 ACCOUNTANTS', Locked = true;
}
I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Hi,

    Can you please correct your GET method with all four key values? There is are Four Keys field in UserGroupPermissionSet table, but you have provided only two.

    f UserGroupPermissionSet.Get(UserGroupCode, PermissionSetId) then

    pastedimage1665738370702v1.png

  • CU30051138-1 Profile Picture
    15 on at

    Thanks for the suggestion.

    I have modified the code like below and now issue is fixed.

           UserGroupPermissionSet.Init;

           UserGroupPermissionSet."Role ID" := PermissionSetId;

           UserGroupPermissionSet."User Group Code" := UserGroupCode;

           UserGroupPermissionSet.Scope := UserGroupPermissionSet.Scope::Tenant;

           UserGroupPermissionSet."App ID" := AppInfo.Id;

           if not UserGroupPermissionSet.Find then

               UserGroupPermissionSet.Insert(true);

  • Suggested answer
    Nitin Verma Profile Picture
    21,812 Moderator on at

    Great.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,250 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,799 Super User 2026 Season 1

#3
AndrewThomas81 Profile Picture

AndrewThomas81 1,390

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans