Legacy Knowledge Base
Published Jul. 2, 2025

Groovy Script Method to Delete Users in Bulk

Written By

Kenny Back

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • I need to delete many users at once from a Liferay instance in a programmatic and efficient way without directly modifying the database (which is not advised).

Environment

  • DXP 7.1

Resolution

  • Below is a template groovy script utilizing actionable dynamic queries to delete users in bulk.
import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
import com.liferay.portal.kernel.service.UserLocalServiceUtil;
import com.liferay.portal.kernel.model.User;

ActionableDynamicQuery adq = UserLocalServiceUtil.getActionableDynamicQuery();

adq.setPerformActionMethod(new ActionableDynamicQuery.PerformActionMethod<User>() {

@Override
public void performAction(User user) {
out.println(user);
}

});

try {
adq.performActions();
}
catch (Exception e) {
e.printStackTrace();
}
  • Additionally, it is recommended to test your script in a lower environment and then backup your database before running in production. 
  • If you find you still need further assistance with Groovy Scripts, feel free to contact your Customer Success Representative to discuss Global Services options. 

Additional Information

Did this article resolve your issue ?

Legacy Knowledge Base