Message Boards
delete liferay user programmatically
delete liferay user programmatically
Junior Member Posts: 47 Join Date: 8/5/14 Recent PostsI tested this code but it does not work :
User u=UserLocalServiceUtil.getUser(11612) ;
UserLocalServiceUtil.updateStatus(u.getUserId() ,WorkflowConstants.STATUS_INACTIVE); //inactive user
UserLocalServiceUtil.deleteUser(u.getUserId()); //delete user
thanks for your help
RE: delete liferay user programmatically
Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent PostsIt throws an exception?
It appears to work but user is still in database?
User shows up in search?
RE: delete liferay user programmatically
Junior Member Posts: 47 Join Date: 8/5/14 Recent Postscom.liferay.portal.NoSuchGroupException: No Group exists with the key {companyId=10154, classNameId=10190, classPK=100601}
RE: delete liferay user programmatically
Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent PostsNormally I never delete users, just mark them as inactive. They cannot log in, they don't appear in searches, it leaves all of their stuff (forum posts, wiki pages, etc.) referencing existing user records, ...
RE: delete liferay user programmatically
Junior Member Posts: 47 Join Date: 8/5/14 Recent Poststhis list contains active and inactive users ! So how can I have just the list of active users ?
thank you
RE: delete liferay user programmatically
Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent PostsRE: delete liferay user programmatically
Junior Member Posts: 47 Join Date: 8/5/14 Recent PostsMy code :
DynamicQuery dynamicQuery = UserLocalServiceUtil.dynamicQuery();
dynamicQuery.add(RestrictionsFactoryUtil.ne("status", 5));
int startOfList = QueryUtil.ALL_POS;
int endOfList = QueryUtil.ALL_POS;
List<user> listuser=UserLocalServiceUtil.dynamicQuery(dynamicQuery,QueryUtil.ALL_POS, QueryUtil.ALL_POS);
</user>
RE: delete liferay user programmatically
New Member Posts: 7 Join Date: 4/8/11 Recent Posts
It throws this exception :
com.liferay.portal.NoSuchGroupException: No Group exists with the key {companyId=10154, classNameId=10190, classPK=100601}
This probably means you deleted the Default User, you can check for this in your code user.isDefaulUser() (returns true/false).
Old post I know but in case anyone else is looking at this.
RE: delete liferay user programmatically
Regular Member Posts: 169 Join Date: 12/11/12 Recent PostsGod post. Almost our problem. I guess that default user has been deleted and with it the group matching these 3 keys. But now we have a new default user with no matching group. How do I recreate matching group? Or can I create a new default user and group is automatically created?asto d:
It throws this exception :
com.liferay.portal.NoSuchGroupException: No Group exists with the key {companyId=10154, classNameId=10190, classPK=100601}
This probably means you deleted the Default User, you can check for this in your code user.isDefaulUser() (returns true/false).
Old post I know but in case anyone else is looking at this.
RE: delete liferay user programmatically
Junior Member Posts: 60 Join Date: 3/16/18 Recent PostsHello,
I am trying to write a Groovy script which helps to delete users based on user id given in the if condition.
import com.liferay.portal.kernel.service.UserLocalServiceUtil
try{
userCount = UserLocalServiceUtil.getUsersCount()
users = UserLocalServiceUtil.getUsers(0, userCount)
for (user in users) {
if(user.getUserId()==36615){
println("User
Name: " + user.getFullName() + " -- " +
user.getAgreedToTermsOfUse()+" Email address:
"+user.getEmailAddress()+" User ID:
"+user.getUserId());
UserLocalServiceUtil.deleteUser(user);
}}
}catch(e){
out.println("""<div
class="portlet-msg-error">${e}</div>""")
e.printStackTrace(out)
}
But, it
gives "com.liferay.portal.kernel.exception.ModelListenerException:
java.lang.NullPointerException"
Please help to resolve the same.
Thanks
Taruchit
RE: delete liferay user programmatically
Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent PostsYou'd have to provide the stack trace. Obviously the model listener is expecting something to be there that isn't, but it isn't clear if this is a Liferay model listener or a home-grown model listener.
RE: delete liferay user programmatically
Liferay Master Posts: 549 Join Date: 4/25/11 Recent PostsHey David,
The stack trace is here:
https://community.liferay.com/forums/-/message_boards/view_message/110981462
However I don't know why Taruchit has not opened a new thread? Taruchit, don't you permissions to open a new thread?
Regarding the issue it seems that the exception is thrown in a Social Office portlet:
at com.liferay.social.office.upgrade.association.internal.model.listener.UserModelListener.onAfterRemoveAssociation(UserModelListener.java:193)
If you don't use it, could you uninstall social office and execute the script again?
RE: delete liferay user programmatically
Junior Member Posts: 60 Join Date: 3/16/18 Recent PostsHello David,
Following is the stack trace for the issue: -
https://community.liferay.com/de/forums/-/message_boards/message/111015368
Taruchit Goyal
RE: delete liferay user programmatically
New Member Post: 1 Join Date: 10/8/18 Recent PostsHI i need a developer to do some work on eCommerce checkout page can any one help me with their right charges.