Delete a User in Sugar CRM

If you have used SugarCRM, you probably have found out by now that there is no easy way to eradicate a user from your database (Check the SugarCRM forum).  I am not sure why this is not an option in the community, honestly, I have not seen the paid version so i do not know if the paid version provides such option.

I have created this stored procedure to help me out and hopefully it will help  somebody else:

1.   First,  you do not want to start deleting. You must first assigned any objects owned by the olduser to another user. To do that you must know the user id of both users (users table find the id column).  Just copy and paste and run the code below on MySQL to create the stored procedure. Then Call the stored procedure using the ids.

something like : Call DeleteReplaceUser (olduser, newuser)

2.   Once you have assigned all objects owned by the disgruntled employee (for example) to the other employee, you can now safely delete the user.

DELIMITER $$

CREATE DEFINER=`admin`@`` PROCEDURE `DeleteReplaceUser`(olduser varchar(20), newuser varchar(20))
BEGIN
-- assigned objects owned by old user to the new user
update accounts set assigned_user_id=newuser where assigned_user_id = olduser;
update address_book set assigned_user_id=newuser where assigned_user_id = olduser;
update bugs set assigned_user_id=newuser where assigned_user_id = olduser;
update calls set assigned_user_id=newuser where assigned_user_id = olduser;
update campaigns set assigned_user_id=newuser where assigned_user_id = olduser;
update cases set assigned_user_id=newuser where assigned_user_id = olduser;
update contacts set assigned_user_id=newuser where assigned_user_id = olduser;
update dashboards set assigned_user_id=newuser where assigned_user_id = olduser;
update emails set assigned_user_id=newuser where assigned_user_id = olduser;
update folders_subscriptions set assigned_user_id=newuser where assigned_user_id = olduser;
update import_maps set assigned_user_id=newuser where assigned_user_id = olduser;
update leads set assigned_user_id=newuser where assigned_user_id = olduser;
update meetings set assigned_user_id=newuser where assigned_user_id = olduser;
update opportunities set assigned_user_id=newuser where assigned_user_id = olduser;
update project set assigned_user_id=newuser where assigned_user_id = olduser;
update project_task set assigned_user_id=newuser where assigned_user_id = olduser;
update prospect_lists set assigned_user_id=newuser where assigned_user_id = olduser;
update prospects set assigned_user_id=newuser where assigned_user_id = olduser;
update saved_search set assigned_user_id=newuser where assigned_user_id = olduser;
update sugarfeed set assigned_user_id=newuser where assigned_user_id = olduser;
update tasks set assigned_user_id=newuser where assigned_user_id = olduser;
update user_preferences set assigned_user_id=newuser where assigned_user_id = olduser;
update users_last_import set assigned_user_id=newuser where assigned_user_id = olduser;

-- Now You are ready to delete the olduser
delete from users where id = olduser;

END$$

reference :

http://dev.mysql.com/tech-resources/articles/mysql-storedproc.html

http://www.sugarcrm.com/forums/showthread.php?t=4896


Let's share thisShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn