cancel
Showing results for 
Search instead for 
Did you mean: 

How to get all customers

0019187810
Explorer
0 Kudos

Hello,

I am trying to create a List with all customers. For as far as I can see, I can get one user at a time (be it the current user, or a userFromUid)

this is what I had been able to do: final CustomerModel cm = (CustomerModel) userService.getUserForUID();

Can anyone tell me how I can get all customers?

Thanks in advance!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I believe you can get the users from getUserService().getUserGroup().getMembers() ;

This will return all the users.

0019187810
Explorer
0 Kudos

Thanks Samudrala, that did the trick for me. I was able to get my Customers out of the list by looping and using instance of.

Thank you!

Former Member
0 Kudos

Vinay, am I correct that the getUserService() should return the object of de.hybris.platform.servicelayer.user.UserService, where the method getUserGroup(String paramString) is deprecated in 5.3?

Answers (2)

Answers (2)

Former Member
0 Kudos

@Vinay

Please note that usergroup.getMembers() will not give you all Users directly, but a hierarchical Structure (Principals) instead. e.g. is willl give you something like this:

 - John Doe (CustomerModel)
 - Jane Doe  (CustomerModel)
 - Subusergroup 1 (UsergroupModel)
 --SubSubUsergroup 1 (UsergroupModel)
 --- Mr. X  (CustomerModel)
 --- Mr. Y  (CustomerModel)
 -- Mrs. Z  (CustomerModel)
 - Foo Bar  (CustomerModel)

to get all CustomerModels, you'd have to write a function that collects all users from sub-groups as well. Or, as an alternative, you could work with Flexible Search/ Write a Dao.

Former Member
0 Kudos

If you're looking for a specific set of users, then try and use a flexible search query. This would be more efficient than returning all the users in a group and then iterating over them.

0019187810
Explorer
0 Kudos

That is a good suggestion. I'll try it that way. Thanks!