As I always say to Laura, it’s amazing how many different ways there are to do something in SharePoint! I would probably do it differently, but that’s not to say that Laura’s approach isn’t a perfectly good one.

In this case, I would use SPServices and the $().SPServices.SPGetCurrentUser function to populate the values with script. The upside of this approach is that you wouldn’t need to customize the form if you didn’t need to for some other reason. You could just add the script to the page, either in the page itself (my recommendation) or in a Content Editor Web Part (CEWP).

One other note on Laura’s approach. If you are populating the list columns with the current user’s Department or Phone, it *might* be a bad idea. If you are really duplicating those values, you run the risk of them changing in the User Information List (via an update from Active Directory, most likely) and having the values in your list be wrong. If, on the other hand, you are using them for some point in time thing (like “What’s your current Department?” in a survey), then you’re fine.

74 Comments

Comment navigation

Both yours and LR’s are great methods, however, your technique also has the huge advantage that it can be done in WSS – I believe LR’s method is MOSS-only since it depends on the Current User Filter web part. Thanks!

I have a similiar but slightly different function I’d like to get to work. Instead of pulling in the current users profile information when the page loads, I need to be able to retrieve user profile information from a person/id entered and verified in the people picker field and then populate fields on the form with that information (department, office, manager). Thank you for any information you can provide.

I work with Rick above, and I’m trying to figure out where to put this code. We have a list called User Info Test, and inside it we have an aspx page called NewForm.aspx. The code as you have it works in in this aspx page, however we are trying to modify it so it will use the onLoad for the PeoplePicker field called Name. The code goes through the page and searches all the elements, looking for Name. Unfortunately it only comes back with one – Search Scope.

I’m new to Sharepoint, so I’m not sure what is going on here. There are 8 different fields on the page.
Not sure if you can help us with this, but here is the code we are using:

Sorry for the delayed reply, but your comment was banished to the spam bucket. You’re doing a little mixing and matching above of JavaScript and jQuery, but probably too much JavaScript. You’ll want to use the Developer Tools (in IE8) or the like to understand how the People Picker is represented in the DOM so that you can bind to the right element’s event. It’s a span that looks something like:

You also don’t want to use _spBodyOnLoadFunctionNames.push when you’re working with jQuery; the equivalent with jQuery is $(document).ready. As it is, I’m not sure what’s going to happen with the code above.

Great!!! I’m able to populate the current user’s Dpartment with your script, yet how about obtaining the current user’s Manager? The following link indicates that doesn’t seem to be part of SPGetCurrentUser http://spservices.codeplex.com/wikipage?title=$().SPServices.SPGetCurrentUser Is there a way to pull the preferred name of my manger with Get_CurrentUserInfo I would like to have a SP list NewForm auto-populate the current User, their Department & Manager.

The fields I have listed in the documentation are the default out-of-the-box fields. If you’ve got a Manager field and it’s exposed on the userdisp.aspx page, then you should be able to retrieve it. The SPGetCurrentUser function does an AJAX call to grab _layouts/userdisp.aspx and “scrapes” the values from the page based on the internal field name (aka StaticName).

Thanks for the post I’m still a bit new to Sharepoint and I was wondering if I could populate a field when a checkbox is checked. For example: I have a Grammar Approved box and a Grammar Approved By field. I would like the Grammar Approved By field to be populate with the name of whoever checks the box. I think the code you provided has the general structure to do this, I just need to know how to adapt it. I’m already using jQuery for some other stuff on my site.

Absolutely. What you’d need to do is bind to the change event on the checkbox and then populate the Grammar Approved field when the box is checked. You can use the SPGetCurrentUser function in SPServices to find out the name of the current user to populate the People Picker.

Thanks for your response. Actually i need to populate the User name and email when user create new item or edit the item so that user no need to enter his information again and again. I have check with Lauras article but it not fully works for my requirement as because of i have more calculated columns in my custom list .

Can you please help me how can i get the user name and email populating

Hi Mark. Thank you for providing this article. I am new to SharePoint and I need help knowing where to place the code that was supplied. The goal is to filter a list by a value specified in the User Information List for the current user. The AllItems.aspx should display the filtered list. Thank you.
– Richard

There are two custom columns in the User Information List. A Division lookup, and a Section lookup. If a user is a member of the Division Manager group, I need to find out which Division they manage, and filter task orders by the DivisionID field. Division managers should have access to all task orders assigned to their Division. If they are in the Section Managers group, I would like to retrieve the Section they supervise, and filter task orders by SectionID. Section Managers should see all task orders assigned to their section. Please let me know the simplest way to do this. Thanks.

Keep in mind that what you display in a view does not guarantee that those subsets of users will be prohibited from accessing the items they don’t see. In other words, you’re trying to layer in some obscurity, but not security.

Your situation is pretty unique, and it will require some custom coding. I would still say that a Data View Web Part (DVWP) with an AggregateDataSource is probably the way to go, though you may need to layer in some script to tie it all together. While what you describe is not tremendously complex, it’ll take some work.

Of course, your other alternative is managed code on the server side, but given the way you’ve asked your questions it doesn’t sound like that’s a realistic path for you.

Think you’ve got great Active Directory data?

Try the FREE Hyperfish Analyzer
Find out just how bad your Active Directory data really is. In your custom report you will see how you are faring with key attributes including Profile Pictures, Phone Numbers, and Job Titles, as well as learn the value of an up to date Directory.