Liferay DXP Free Tier    |    From download to running in minutes    |    Get started →

Blogs

Searching entities through custom attribute value.

Sushil Patidar
Sushil Patidar
阅读少于一分钟

If you need to search Users who has particular custom attribute value .Using liferay expando API ,this can be acheived easly as follows.

String attrValue ="IT";
 
String attributeName ="user-department-name";
 
String tableName = ExpandoTableConstants.DEFAULT_TABLE_NAME;
 
long classNameId = ClassNameLocalServiceUtil.getClassNameId(User.class);
 
 
List<ExpandoValue> expandoValues =ExpandoValueLocalServiceUtil.getColumnValues(companyId, classNameId, tableName, attributeName, attrValue, -1,-1);
 
 
for(ExpandoValue expandoValue:expandoValues)
 
  try {
      long userId = expandoValue.getClassPK();
      User user  =UserLocalServiceUtil.getUser(userId);
  }
  catch(NoSuchUserException nsue) {
 
   _log.error("No Such User Exist");
  }
}
 

 

页面评论
Wow, how did I not see this!! Thanks Sushil, super helpful!

Related Assets...

未找到结果

More Blog Entries...

Ben Turner
十一月 26, 2026
Himanshu Chauhan
十一月 20, 2026
Tony Lim
十一月 19, 2026