Sorry, the current permissions prevented the action (Table data modify)

CelicniCelicni Member Posts: 10
edited 2024-07-19 in NAV Three Tier
This is BC22.

I have made a table to store user login data from all companies. It is a simple table with two fields (field(1; "User ID"; Code[50]), field(2; "Last Login DateTime"; DateTime)).

The table has DataPerCompany = false; so it will record logins for any company.

Here is the code that is giving me the error:
[EventSubscriber(ObjectType::Codeunit, Codeunit::"System Initialization", 'OnAfterLogIn', '', false, false)]
    local procedure UpdateLastLoginInfo()
    var
        LoginHistory: Record csa_User_Login_History;
        lastLoginDuration: Duration;
    begin
        if UserId <> 'SYSTEM' then
            if LoginHistory.Get(UserId) then begin
                lastLoginDuration := CurrentDateTime - LoginHistory."Last Login DateTime";
                if (lastLoginDuration > (5 * 60 * 1000)) then begin
                    LoginHistory."Last Login DateTime" := CurrentDateTime;
                    LoginHistory.Modify(false); <------ [b]this line right here errors out[/b]
                end;
            end
            else begin
                LoginHistory.Init();
                LoginHistory."User ID" := UserId;
                LoginHistory."Last Login DateTime" := CurrentDateTime;
                LoginHistory.Insert();
            end;
    end;

The debugger will randomly error out on the LoginHistory.Modify(False) line with the message (visible only from the event viewer, it doesn't actually show up in the client):
Error Code:18023831
Sorry, the current permissions prevented the action. (TableData csa_User_Login_History User Login History Modify: Chase Base Application)

the codeunit has Permissions = tabledata "csa_User_Login_History" = RIMD;

My thinking is it's got something to do with it being a multi-company table, and lacking permissions to modify it in the other companies.

Does anyone have any ideas? It's really annoying to get a breakpoint error randomly.

Answers

  • TallyHoTallyHo Member Posts: 417
    https://yzhums.com/17290/

    Seems like existing functionality.
    If it is very important to you that it registers for all companies, just write code that automatically turns this on when a new user setup record is created, and activate it on all others
  • CelicniCelicni Member Posts: 10
    This is less about implementing this exact functionality and more about wondering why it errors out at that specific line.
    Also, looking at what you linked, not sure it'd fit what they want.
  • TallyHoTallyHo Member Posts: 417
    edited 2024-07-22
    Or the session event table might help.
  • TallyHoTallyHo Member Posts: 417
    Or try subscribing on another event. Incompany open?
Sign In or Register to comment.