Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am an intern at a company, so I am not completely sure about the structure of the servers etc. However, I have a library that I want to filter by the department that the currently logged on user is in. The the department that the user belongs to as well as other details should be stored on the AD.

The library is a simple document library with a few added columns that contains some meta data. Among this data is the department of the person who uploaded the specific document. Hence, for every user who opens the library, I want to show only the documents uploaded by users in his own department.

What I've tried to do was making a parameter with SharePoint Designer on the ListViewWebPart on the AllItems.aspx page and set the department of the current user in this parameter. It appears that it will then be a simple matter to filter by this parameter and the Department column in the library.

Problem is, I have no idea how to go about getting the appropriate value in the parameter. I tried making the parameter a Server Variable and using LOGON_USER and then search for the user in the 'User Profiles' list that seems to be on the system, but after hours of tinkering have made no progress.

Any help will be highly regarded.

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

If you are using the Enterprise version, you can pull this off by placing a User Filter web part onto the page and configure it so the current user's department is passed to the web part and filter the department field in the list. No code, ootb functionality, if you have the Enterprise version.

share|improve this answer
add comment

You can use the SharePoint Javascript OM to access the SharePoint Security Context and get the user name of the current user. it SP.ClientContext.CurrentUSer

<script type="text/ecmascript" src="/_layouts/SP.Core.js" />
<script type="text/ecmascript" src="/_layouts/SP.Debug.js" />
<script type="text/ecmascript" src="/_layouts/SP.Runtime.Debug.js" />

    <script language="ecmascript" type="text/ecmascript">

      function onQuerySucceeded(sender, args) {
          alert('Title: ' + this.oWebsite.get_title() + ' Decription: ' + this.oWebsite.get_description());
      }

      function onQueryFailed(sender, args) {
          alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
      }

      function retrieveWebSite() {
          var clientContext = new SP.ClientContext.get_current();
          this.oWebsite = clientContext.get_web();
          clientContext.load(this.oWebsite);
          clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
      }
  </script>

This is a sample script. But you should get the idea you can use this to communicate with SharePoint and get the CurrentUser

share|improve this answer
add comment

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.