Recently, I tried to delete a user from a Dynamics NAV 2013 database but got an unexpected error message: “The user cannot be deleted because the user has been logged on to the system. You must set the user’s state to Disabled”.
My first thought was that the user was logged on into the database at that very moment, and that NAV was preventing me from deleting an user with an active session. But when looking into the session list it appeared that the user did not have an active session.
Next thought was that NAV asked me to prevent the user to log in by setting the user state to Disabled. But that proved to be wrong:
So what to do? Luckily, one of my colleagues knew the trick: delete the user personalization.
And yes, after deleting the record for the user from this list, I was able to delete the user record.
This personalization record is created automatically when a user logs in the first time. It is updated each time the user exits the application with the latest used language and company the user was logged in to. So NAV interprets the existence of this record as ‘the user is active’ and prevents you from deleting the user. Not a very informative message, and in my opinion not a very nice design either.
But now you know how work around this message!
– UPDATE –
After I wrote this post, I got an email from Microsoft with an explanation that this behavior is by design. For audit reasons it should not be possible to delete a user, who has performed a transaction in the database. Because a user who has ever logged in, has a record in the User Personalization table, they choose to test this table. So the error message must read: “The user cannot be deleted because the user has probably performed a transaction in the system. You must set the user’s state to Disabled”.
I have suggested to check the G/L Entry table rather then the User Personalization table. Probably more tables are needed, I don’t know, I’m not an auditor. Anyway, if you are sure that the user hasn’t performed any important transactions, feel free to use the described workaround. If you are not sure, or want to save the user because of auditing reasons, just disable the user.
Pingback: Dynamics NAV user cannot be deleted - Microsoft Dynamics NAV Thoughts - Dynamics User Group
Ran into the same issue this week. Thanks for the post
“For audit reasons”: always an easy excuse for things like this. I do not agree, because records with the id of the user are not removed from the database, when removing the user. Afterwards you can always create overviews from G/L Entries of other records filtered on the user-id.
Thanks for the post, fixed a pesky problem for me without having to contact our reseller.
I have been facing a issue while disabling the user. The system does not allow me to disable users as it says the table is locked even though the user is not working on it.
thank you man, I ran into same problem :). I wanted to delete test user in order to create it again and debugger did not stop so I could not find reason.
Thanks, it’s crazy that something this basic has such a stupid error message which puts you on the wrong track.
One thing that’s not allowed to delete the user in Navision – But can I delete the user in AD – and should I ?
Sure, why not? Nothing prevents you from deleting the user in AD. It will persist in NAV, though.
Thank you for sharing this important information. Helped me to understand why such errors appear when you delete a user in NAV.
Thank you. The very same issue exists in Nav2018.
Microsoft still could not simply just update the error message.
FYI: The PowerShell cmdlt Remove-NAVServerUser runs into the same problem.
It seems the only workaround to remove users with PowerShell is to create a sql query that deletes user records.
Or does is there another ‘easier’ way to remove users with a PowerShell script?
I don’t think it is possible to do this with PowerShell only. The user personalization record needs to be deleted first, and there is no PowerShell command for that.
Set-NAVServerUser xxxx -WindowsAccount yyyy -State Disabled
but will not work if user is disabled in AD
Set-NAVServerUser BCISTOPSERVICENAME -WindowsAccount LOVEMYUSER -Tenant MYLOVELYTENANTNAME -State Disabled