0

My users profiles contain a field with department name.

How can I make the unique values from department available in a select list within a content type field? i.e. Sales, Marketing, IT, etc. (to avoid duplicates).

UPDATE:

I created Entity Reference > Select List > User (target type) + a view with ER that contains the user profile field department, but Query settings DISTINCT still doesn't get rid of the duplicates.

I even tried views_distinct module with Filter Repeats.

0

Try using aggregation. Set this value in your View under Advanced > Use aggregation. The Group Results Together aggregation type should be the default and should provide the behavior you're looking for.

If this isn't quite what you're looking for, please export a copy of your view configuration, from Configuration > Development > Configuration synchonization > Export, then select Single and find your view under the Views dropdown and update your question with this export.

| improve this answer | |
  • Thanks Beau, actually I tried aggregation yesterday and while it listed all items only ones in the view yet they all get listed in the ER field select list individually, as if it can't interpret grouped results. I managed to get it done via another module called views merge rows, but I'm just stunned that such simple task won't properly work with distinct query or the distinct views module. While the value of department names get only listed ones in the ER field during node edit, yet when displaying the field it uses for label the user name of that deparment name field from (1st occurrence). – Markus May 3 at 16:08
  • I'll try later on to export and share the view, your help is much appreciated and prefer to get this working so I can lead and perhaps use it in other scenarios. Btw. In case you have any ideas how I can change the Format of the ER field in manage display, let me know. I tried the views mode module but it doesn't provide customisation to the actually ER field format, just layout / setup for all fields. – Markus May 3 at 16:09
  • I had a similar use case recently. I have an entity, Corp, with an unlimited cardinality entity reference field to a Zip entity. Users search on the Zip entity, but I also wanted to display the list of applicable zips per matching Corp. I used Display Suite's expert field template and modified the display of the Zip entity reference field by just assigning 'select' as the Field items element and 'option' as the Field item element, and it produced a dropdown of referenced zip codes. If you'd like more detail, please post a separate question and I'd be glad to provide more details. – Beau May 3 at 16:23
  • meant to say "so i can learn more...", thanks Beau for sharing. I actually discovered a bigger problem (regardless of using the filtering/merge rows, even with just listing the user field department in the view) when editing the node field it displays those department names for selection but when actually viewing the node that field displays the users id instead (target_id). I opened another question, wondering if the "Display Suite" you mentioned would help solve this or you might know a simpler way, thanks. drupal.stackexchange.com/questions/293337 – Markus May 3 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.