SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a list view that should only show when an admin adds the person's username to an "allowed viewers" username column. So, I am thinking to create a calculated column that compares the current-viewing user to the username in the "allowed viewers" column. Then, I will filter the list by the result. If it compares to true, the list item will show. If it compares to false, it will not show.

So my question is, what do I put in the Calculated Column field to compare my "allowed viewers" column (which contains a username) to the current user?

[waaaay later]

Well, I've never come to a satisfactory solution to filtering a list by the current username, and got into more trouble here. I'm adjusting the title of my question to better reflect my intention.

How can I use a username column and filter the view by the matching current user?

share|improve this question
    
Can't you just set the permission on the list? SharePoint will handle permission trimming for you. – Hugh Wood Nov 20 '12 at 15:32
    
No, because I am using the list as a template to be set on 100 sites where each site has a different group assigned with rights to manage everything but views. – bgmCoder Nov 20 '12 at 15:38

Okay had a play and basically use "Me".

Either:

// Include domain name
Me

// Remove domain name
RIGHT(Me, LEN(Me) - FIND("\", Me))

Note: Column names are in the format [column]

share|improve this answer
    
can we use calculated columns with multi-select person field ? – Arsalan Adam Khatri Nov 20 '12 at 15:52
    
Yes, I have seen it done, filter the data perhaps with find? since it is stored as plain text, "Name; Name1; Name2", this part is a little fuzzy but I think it should be fine. – Hugh Wood Nov 20 '12 at 16:19
    
Uh, how do I use that to compare Me with the username value in the "allowed users" column? The "allowed users" column will be a multi-select field, by the way. – bgmCoder Nov 20 '12 at 16:23
    
The logic would be something like "if(FIND(ME, [column]) > 0, TRUE, FALSE)" I can't test this on my current setup however. – Hugh Wood Nov 20 '12 at 16:26
    
Ah, it says I can't use columns defined as username data types for a calculated value... – bgmCoder Nov 20 '12 at 16:33
up vote 0 down vote accepted

After having spent hours and hours trying to get columns and calculated columns and workflows to come up with some combination that might match the current user against a value in a list-view field, I finally managed to come up with something.

In the end I used a Current User Filter. The idea came from here. But here is my take on the procedure:

The List-View page is already a Web-Part Page with a list-view web-part, so I:

  1. Entered Edit Mode
  2. Added a Current User Filter - you will find this when you go to add a new web-part to the page. It is under Filters.
  3. Using the drop-down arrow for the Current User Filter web-part (in the upper corner) I used 'Create Connection' and set the list-view as the recipient and I chose which column I wanted to filter - which is a regular person field.
  4. Then, in the Current User Filter's web-part options, there is a place where you can specify how the value is returned. I set it to Name. This way it will return a Display Name instead of a domain user account name (see screenshot below).

Here is an image:

Options for Filter Web Part

That's it!

Summary

I added a Filter Web Part to the Web-Part Page and connected it to the List-View and set the return value. This works like a charm. Now I have a list filtered to show only those items where the username column matches the currently logged in user. And it's all OOTB and scriptless.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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