Quickly enable or disable users through code
A while ago I got a question from someone how to disable a bunch of users quickly. So I needed a way of end-dating these users so they are unable to login. Of course this can be done by running a dataloader script, by doing a dirty update to the FND_USER table but a more supported way is by using the public procedures of the FND_USER package FND_USER_PKG. A question that can be asked after that.....but how can we enable a user again through code? Let me explain.
Disable an user
Run the below statement to disable a user immediately per sysdate. Take note of the required commit call after the disable procedure. As always change the parameter username to fit your needs.
BEGIN
FND_USER_PKG.DisableUser(username => 'CSCHAIK');
commit;
END;
After this the user account is assigned an end-date of sysdate and the user status changes to Inactive.
Enable an user
If you want to enable an user again the below snippit can be run.
BEGIN
FND_USER_PKG.EnableUser(username => 'CSCHAIK');
commit;
END;
This will remove the end-date of the user account and makes it active again. The EnableUser procedure also has optional parameters for the start and end-date of the user. For example running the below command will enable the user per sysdate but setting an end-date of sysdate + 30 days.
BEGIN
FND_USER_PKG.EnableUser(username => 'CSCHAIK',
start_date => sysdate,
end_date => sysdate+30);
commit;
END;
The above can also be used to enable an user in the future. For example the below will enable a user per sysdate + 2 days. Note that as per sysdate this user is still Inactive but will become Active 2 days after it.
BEGIN
FND_USER_PKG.EnableUser(username => 'CSCHAIK',
start_date => sysdate+2);
commit;
END;
As always, have fun!