views:

1815

answers:

3

i have a list that have a user/group column that i want to filter by (the column name is: USERS). how do i get only the items in the list where the current user exists in the USERS column?

A: 

If it is simply a customized view, look at a Tasks list and the My Items view for reference.

You should be able to go the the Filter section in the view and have a filter that has "is equal to" "[Me]". However, it sounds like this is a multi-valued field so maybe you can get away with "contains" "[Me]".

Another considerations is looking into Audiences if you have MOSS. The Content Query Web Part is capable of filtering list items based on the audience.

Kirk Liemohn
kisin
I believe this is wrong. SharePoint 2007 won't let you user the contains operator on a Person or Group column, even if select multiple is enabled.
RossFabricant
A: 

Hi Kisin,

I do have a similar requirement, I have a column with users or groups (multiple users / groups mixed together) . I want to apply filter. Did you get the answer ? This helps me a lot. I have to implement this in WSS ..

Thanks in advance Jagkon

jagkon
A: 

jagkon, i used this code to go over the column and check each item:

                            if (item["users"] != null)
                            {
                                //get USERS field for item
                                SPFieldUserValueCollection fieldUserValueCollection = new SPFieldUserValueCollection(web, item["users"].ToString());

                                //go over the users/groups collection
                                foreach (SPFieldUserValue fieldUserValue in fieldUserValueCollection)
                                {
                                    if (fieldUserValue.User == null) //group
                                    {
                                        if (web.SiteGroups.GetByID(fieldUserValue.LookupId).ContainsCurrentUser)
                                        {
                                            bolItemGood = true;
                                            break;
                                        }
                                    }
                                    else //user
                                    {
                                        if (fieldUserValue.User.IsDomainGroup) //domain group
                                        {
                                            if (web.IsCurrentUserMemberOfGroup(fieldUserValue.LookupId))
                                            {
                                                bolItemGood = true;
                                                break;
                                            }
                                        }
                                        else //sp user
                                        {
                                            if (fieldUserValue.User.LoginName == Context.User.Identity.Name)
                                            {
                                                bolItemGood = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
kisin