Liferay - Get User Based On Expando Value

Use below code snippet if you want to search users based on expando value. In below snippet ColumnName is the name of custom attribute (expando attribute) and data is expando value.

One more point i would like to highlight here in below snippet we are looking for exact value of custom attribute . In few cases you might not have exact value of custom attribute in that case you can alter dynamic query and instead of eq you can use like query. For more information on dynamic query you check this post.

Next PostNewer Post Previous PostOlder Post Home


  1. Hi,
    Here I would like to add small modification. You are using iteration of expandoValue. Instead of that you can use DynamicQuery for User class like below. This will increase the performance.

    DynamicQuery userDynamicQuery = DynamicQueryFactoryUtil.forClass(User.class, User.class.getClassLoader());
    List users = UserLocalServiceUtil.dynamicQuery(userDynamicQuery);

    1. Yes , I agree that is also a way to get the using dynamic query.

  2. Hi there,
    Have you ever tried searching for a custom field of type date by a date range (e.g. all users with last vacation date < 180 days?).
    We figured that the date is stored as a string of milliseconds, but dynamic query filter would do a string comparison and no comparison of numbers.

    Do you have any idea how to solve this?