Jonas Lindau
Mar 14, 2014
  1558
(1 votes)

Relate+ - Get distinct values from attributes

Recently I had to figure out a way to get all distinct values from a certain attribute in a Relate+ project. The site uses a lot of attributes on IUser to store local copies of attributes in Active Directory. These attributes are then used mainly for presentation, but know they want to filter on these attributes. Filtering on an attribute is quite easy, the issue showed to be getting distinct values for a certain attribute to for example populate a dropdown.

The only solution I found was to use LINQ on a UserCollection. It works great, but the downside might be performance. Because of this, I figured I create a InitializationModule which load all distinct values from the needed attribute and store them in the cache. Then, all I have to do is getting the list from the cache when needed.

There are many good articles on how to create InitializationModules, so I’m going to leave that part out. But here is how I get all distinct values for the attribute “OrganizationAbbreviation”:

   1: UserCollection Users = CommunitySystem.CurrentContext.DefaultSecurity.GetUsers();
   2: string[] Units = (from CurrentUser in Users where CurrentUser.GetAttributeValue<string>("OrganizationAbbreviation") != null select CurrentUser.GetAttributeValue<string>("OrganizationAbbreviation")).Distinct().OrderBy(x => x).ToArray<string>();

Now I can easily populate all my dropdown-lists with the organizational units!

Mar 14, 2014

Comments

valdis
valdis Mar 14, 2014 01:15 PM

Even going further - you may want to get rid of "stringly" typed interface when working with Relate attributes. This may become handy tool: https://github.com/Geta/Community.EntityAttributeBuilder

Please login to comment.
Latest blogs
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024

Frontend Hosting for SaaS CMS Solutions

Introduction Now that CMS SaaS Core has gone into general availability, it is a good time to start discussing where to host the head. SaaS Core is...

Minesh Shah (Netcel) | Jul 20, 2024

Optimizely London Dev Meetup 11th July 2024

On 11th July 2024 in London Niteco and Netcel along with Optimizely ran the London Developer meetup. There was an great agenda of talks that we put...

Scott Reed | Jul 19, 2024