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

Notifications

Announcements

No record found.

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,698 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,698 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans