SharePoint List Form – Default User Information

In MOSS Enterprise, there are some great “Filter” out of box web parts.  In this post, I’ll explain how you can use the Current User Filter web part to send default information about the current user to multiple fields in a regular SharePoint list form.  A while back, Lori Gowin blogged about how to auto-populate InfoPath Form fields with current user information.  Also, in the past year, Mark Rackley has blogged about how to send a query parameter to a form field in a SharePoint list form.  Today, I’m going to combine these two different ideas, and show you how to auto-populate SharePoint List (not InfoPath) form fields with property information about the current logged in user.  This does involve some code-tweaking and patience, so thanks for bearing with me.  😉

In this example, users fill out a form on your site, and this form contains fields called Department and Phone, that we want to be automatically populated in the form.  This entails creating a custom “New Item Form” for the list.  Ahead of time, I’ve created a list in SharePoint, with Department and Phone created as “single line of text” columns.  The end result will be that when any user clicks to create a new item in a list, these two fields will be filled out already, like this:
CropperCapture[104]

    1. In SharePoint Designer, navigate to your list on the left side of the screen, and find the file called NewForm.aspx.  DON’T modify this default form.  Create a new one by simply copying that one and pasting it in the same location.  It will default to the name NewForm_copy(1).aspx, but you can just change it to something like NewFormCustom.aspx.  If you need more info about this first step, I’ve created a video you can watch.
    2. Delete or hide that default (only) web part on the aspx page, because you’re going to create a new custom one.  Put the cursor inside of the only web part zone on the page, and click the Insert menu at the top of the screen, choose SharePoint Controls, and then Custom List Form.  The name of my list is TestList (I know, real original), and be sure and pick the New Item Form here.
      CropperCapture[95]
    3. Next step is to create a parameter in the data view web part, for each field that we want to auto-populate.  Click the Data View menu at the top of the screen, and click Parameters.  Click the New Parameter button.  Create the following 2 new parameters, both with the parameter source as Query String:
Parameter Query String Variable Default Value What is it for?
ParamDept UserDept This will pass the user’s department name to the Department field in the list
ParamPhone UserPhone This will pass the user’s phone number (Business Phone) to the Phone field in the list
    1. When your screen looks like this, click OK
      CropperCapture[96]
    2. The next step is to convert the Department and Phone form fields into Text boxes. Click to select the Phone field, and click the little chevron next to it.
      CropperCapture[97]
    3. In the Format As drop-down box, change it to Text Box.  Do the same for the Department field.
    4. The next step entails some code tweaking, so click the Split button at the bottom of the screen.  When you click to select the Phone Text box, you’ll see that associated code is automatically selected in code view, like this:
      CropperCapture[99]
    5. Look to find the part of the code that says text=”{@Phone}”  This is where that parameter information comes in handy.  For the phone, we called it ParamPhone.  So, we need to change this part of the code to say the following instead: text=”{$ParamPhone}”
      VERY IMPORTANT!  Notice that the @ has been replaced with a dollar sign here.  I missed this part the first time I did this, and Mark Rackley was very kind to help me out and find that tiny little error.  😉
      Okay,  now do the same for the Department field.
    6. SAVE this form, and click the F12 key to open it in the browser.  You can close the form in SharePoint Designer.
    7. IN THE BROWSER… Click Site Actions, and Edit Page.  Click to Add a Web Part, and add the Current User Filter to the page.  Do this twice, so that there are 2 current user filters on the page.  You will add an additional current user filter web part to represent each field in the form that you want to be auto-populated.  So, in this form we have two… Department and Phone.
    8. CropperCapture[100]On the first Current User Filter web part, click to Modify Shared Web part, so that you’ll see the Web Part Tool Pane on the right side of the screen.  Configure it like this:The Filter Name is Phone, and for the SharePoint profile value, pick Work Phone from the drop-down box.  At the end of this post, I’ll tell you more about where this drop-down info comes from.In the Appearance section, I changed the Title to “Current User Phone”, but that’s optional, since this title and web part won’t be seen by end users anyway.
      Click OK at the bottom of the web part toolpane.
    9. Now, for the second Current User Filter web part, do the same thing, like this:
      Filter Name – Department
      SharePoint profile value – Department
      Appearance/Title – Current User Department
    10. The next step is to create the web part connections, to pass the current user information into the new item form, into the parameters that we created.  At the top right corner of the list web part, click Edit, and choose Connections.  Choose Get Parameters From, and then click Current User Phone (remember this is what I named the Title of the web part in the screenshot above).
      CropperCapture[101]
    11. Choose the ParamPhone in the Consumer Field Name drop-down box.  This is the name of the parameter that we created in the table at step 3.  Click Finish.
      CropperCapture[102]
    12. Next for the department… At the top right corner of the list web part, click Edit, and choose Connections.  Choose Get Parameters From, and then click Current User Department.  Choose the ParamDept in the Consumer Field Name drop-down box.  Click Finish.
    13. Click to Exit Edit Mode.  You’ll see that those two fields will automatically be populated based on the information about you the logged in user.
    14. The next step is to configure SharePoint Designer so that it uses the new “New Form” by default.  In SharePoint Designer, right-click on the name of the list on the left side of the screen.  Click Properties, and go to the Supporting Files tab.
    15. Change the Content type from folder to whatever the other choice is here, such as Item.  Next to New Item Form, click Browse, and go to the new custom file you just created, and click OK.  Click Apply and OK.
      CropperCapture[103]
    16. Test it out.  Go to your list in SharePoint, and click NEW.  Your new item form will be displayed, with the 2 fields filled out for you.
    17. Now, you can even take this a step further, and hide these filled-in fields from the user, as Mark has explained in his post.  Basically, in the form’s code, you have to tweak the TD (table cells) for each cell in the row that you want to hide, so the code would look like this:

<td width=”190px” valign=”top” class=”ms-hidden”>

Where does the Current User information come from?  Again, this is a MOSS Enterprise thing, and it comes from the user profiles and properties information in the SSP.  The profile properties seen in the current user filter web part have to be set up in the SSP to be seen by “everyone” and set as “replicable”.  Also, if a property doesn’t exist, such as “Zip code”, you can add it in User Profiles and properties list of properties, by clicking New Property.  Basically, you have to pick which field in Active Directory to map to the new property in the SSP.  Here’s some TechNet info on User Profile Properties.

Here is my video showing this whole solution

75 comments

  • christine.taylor@nwtc.edu

    Thanks for this article Laura. Is there any way to return the user to the previous page (the page where the link to the list form exists) after submitting a new item via the list form?

  • christine.taylor@nwtc.edu

    Laura, I actually just found a post from you in a blog on tech net that talks about changing the “&Source” parameter to the originating page. This worked for me. Please disregard my previous post, unless the answer may be helpful to add for other readers Thanks much!

  • This is the coolest thing ever! Thank you so much for sharing, Laura!

  • Laura, is there any way to make this work in WSS? Thanks!

  • Thanks Laura very good explanation and instructions and with very little tweaking I was able to use this same process on SharePoint Server 2010 Foundation, works like a charm. Thanks!

  • ddiallo@gmail.com

    Hi Laura, I did all instruction, but i m getting empty propertis list box on SharePoint profile value for current user. Any help? Thanks

  • Thanks for the information. Is there a way to utilize similiar functionality to retrieve user profile information from the results of a people picker look up?

  • Hi Rick, When you create a “person” field in SharePoint, on the new column screen, it gives you the option to pick which field from the profile to display. So, one thing I’ve done in the past is to create those fields like with the person’s department name or whatever, and then set a workflow to copy the “created by” field’s data over to those other fields when an item is created.

  • manuelfelipepardo@hotmail.com

    Hi laura… well the “Current User Filter Webpart” dont seems to be available… what can I do?

  • Manuel, Do you have MOSS, or just WSS? If it’s not MOSS, then the web part won’t be available.

  • akilaskk@yahoo.co.in

    Hi, Thanks for this blog, it is really helpful for me, and it works fine, but, while click on ‘ok’ after filling the required fields, im getting the the error “The data source control failed to execute the insert command”. Im having MOSS 2007. Any help?

  • This is great. Does this work in Sharepoint 2010

  • Nick, Yep!

  • Hi Laura, how can i make the same procedure work on a Document Library not list

  • tom.graf@cfl.lu

    Hi everybody, The Current User Filter Webpart only exists in MOSS Enterprise Edition. It’s not available in MOSS Standard Edition. PS. This is valid for MOSS 2007. I don’t know if it’s still the case in MOSS 2010.

  • Hi laura, I am using WSS 3.0 and I want logged in user name into list field. How can i do that? Plz reply me as soon as possible.

  • I’m wanting to apply this to a Contacts list (I don’t know why) and had success with WorkPhone and FirstName but it blew up on me with I attempted to set LastName to the Title. Was it my error or to be expected?

  • bcaldera@sbcounty.gov

    Hi Laura, I was able to run thru your examples in our DEV area and when I felt confident I tried it in our PROD area. Ugh! I guess I was too confident and in a nurry. I now get a Invalid URL and I guess from what I can tell somehow removed the ListFormWebPart? Any easy to follow instructions of how to repair this? Thanks Bob

  • Not sure how this would be done in a document library. I haven’t tried it. Also, I haven’t tried this on the Title field (Last Name), but I can see that it would act differently because it is “special”. Not sure how to get around that. Also, since this solution is a data view web part, it’s not necessarily going to work if you take the whole site and create a template from it or otherwise try to copy it to another location. I’ll have to do a screencast on the whole “ListId” versus “ListName” thing.

  • sanket.pandya24@gmail.com

    Hi Laura, I want to filter EWA webpart with current Login user. It is possible with choice filter webpart but is there any way to do it with Current User Filter webpart? Or how to set current Login user as default value of choice filter webpart? Waiting for your response… Thanks

  • Hi Sanket, Yes, you can do that. When you publish the Excel spreadsheet to sharepoint, you have to put the proper parameters in it, according to whatever data you want to filter. Like if you have a column called “marketing” in the spreadsheet, the filter box for it has to be a named range, and a parameter. Then, use the current user filter web part to send the current user’s “department” to the EWA web part using a connection. http://office.microsoft.com/en-us/sharepoint-server-help/connect-filter-web-parts-to-excel-web-access-HA010105470.aspx

  • can I get the proper username – not the login name with this? Like gets populated in Create By?

  • Stephanie, Are you referring to the people picker control? You’re right, this is not a people picker, and getting one of those to auto-populate I possible I think, but it entails Javascript or JQuery or something.

  • Hi Laura, Thanks for another useful article. I was interested in your reponse (dated 6/17/2010 9:00 AM) the Rick’s question that suggested the use of a Workflow to populate ‘Person’ fields in a list with different profile elements set. You mentioned you did this based on the ‘Created By’ fields data. What I would like to do is use the data from an initial ‘People’ field to populate the rest of the list fields when the item is created. Do you have any pointers to where I could find information on how to create such a workflow? Regards

  • Hello Laura, Great post ! I have a weird issue though. I created a test site and modified with all the above steps as you suggested in SPD under my login. When i go back to the site and say ‘New’ my name is auto populated. However when somebody else does it, it redirects to the NewForm.aspx instead of NewFormCustom.aspx and all that they see is a blank white page. What am i doing wrong here ? I even tried on my laptop by logging in with a test id and it doesnt work. It works only under my name Thanks !

  • M, It’s because you haven’t set that form as the default one, probably. Please watch this screencast: http://www.endusersharepoint.com/2009/09/11/customize-form-pages-in-sharepoint-screencast/

  • Laura, Thanks for your reply. However, I already set the New Custom form as the default by following Step 18 in your instructions above if that is what ur referring to. When i login as me custom form pulls up with no issues but if i login as a test user or anybody else tries to pull up the list by saying ‘New’ it doesnt work. I created the custom form in SPD under my login. Not really sure what is causing the issue

  • Hi Laura, great post, but I’m running into problems at step 14 & wondered if you had any pointers for me? I click “finish” on the “configure” dialogue, but then get told “An unexpected error has occurred” – which isn’t very helpful! Do you have any idea of where I should start looking for problems? Cheers George

  • George, I don’t know, I’ve never seen it do that. The only thing I can think of is if they’re clicking on a URL to the new form that was created manually. But if they’re just clicking the regular New button on the list, it should give them your custom form.

  • Laura, I was able to resolve the issue. Very silly of me but I realized that the test sharepoint account that i was using was missing from user profiles on my test farm. Once i had it imported everything worked fine. Thank you 🙂

  • Hi Laura, great post, but I’m running into problems at step 14 & wondered if you had any pointers for me? I click “finish” on the “configure” dialogue, but then get told “An unexpected error has occurred” – which isn’t very helpful! Do you have any idea of where I should start looking for problems? Cheers George

  • Dmcgaw@healthplus.org

    Got it working like a charm but it breaks if I add to to a list that has attachments. If I disable attachments it works just fine. Any suggestions?

  • I use this exact method a lot, but have found a peculiar problem. When I connect the web parts, the validation on the new item form doesn’t seem to work. I have a date field on the list that is required, but if I enter an invalid date and submit, the form refreshes, but no “You must specify a value for this field” message. If I disconnect the Current User Filter, then the form works (and validates) correctly. Have you encountered this? Thanks for posting. Rich

  • teipel.eckd@erzbistum-koeln.de

    hi laura! your solution works fine. but if i set the listformfield into a textfield, i will loose the function to check the filling of the fields. In a Listformfield there is a check, if the field contains content. after setting the fields into textfields there is no check and no advice on the form. any idea? kind regards Carsten

  • dmcgaw, here’s my post about the attachments breaking issue: http://wonderlaura.com/2009/2/18/fix-for-the-custom-form-attachments-issue
    Rich and Carsten, Right, the regular built in validation won’t work for that text field, so here’s my post about doing the validation: http://wonderlaura.com/2010/6/26/phone-number-validation-in-sharepoint-2007

  • Hi Laura Thanks for the post. Everything works fine but data is not reflecting in the list. I did everything as u suggested and im able to get the values in the new form. But the data is not getting updated in the list once i press the OK button. any idea

  • This is exactly what I was looking for and it worked like a charm… until I opened the same file back up in Designer and added some static text to the page. As soon as I save the file, press F12, I get a blank shell of my page. No error, just my master page. Any ideas? I’m assuming SharePoint Designer is altering something else when I open it again that I’m not catching? I’ve done it enough times now that I simply go in, add one letter, press save, nothing. I hit “undo”, still broken. Thankfully I saved a back-up now just before the “break”, but I can’t customize the look of the form now. Any clues?? I’m so stuck!

  • Anoop, Maybe the text box didn’t get connected to the right data field, double check that you did step 5. tlocke, I’ve had strange things like that happen to me. Silly DVWP is so picky sometimes. Often I have to scratch and start over, which is why I never modify the original form aspx files.

  • Hi Laura, Great article, but I’ve run into an issue in SP 2010. I’ve successfully modified the New Item form to display the user data I want (phone number) on the New Item form itself, but saving the new item doesn’t write the prepopulated phone data to the list. Here’s the code for the form field before modification: And here it is after changing it to a text field: I can’t see the complete code for step 7 of your article, but it looks as if SPD 2007 and 2010 are handling the format change of the form field differently. In any event, the prepopulated phone number isn’t hitting the list. Any ideas? Thanks

  • Hi Laura, Wondering if you can help me, but is it possible to set the filter to look at another list? what I am wanting to do is create a list with the peoples name and pay numbers in, then it automatically pulls the pay number throuh for the logged on user. Unfortunately I do not have server side access so I have to work with basics. Hope you can help

  • RogerS, It’s done a little differently in 2010. Instead of converting to a text box, just delete the control completely and insert a text box from scratch, from the list of data view controls. Thomas, Yes, you could use a workflow to do it, but it wouldn’t be dynamic as they’re filling out the form. The workflow would have an action that would be “Set field value…” and you’d set the value of the pay number to the value of the pay number from the other list, where the employee name matches.

  • Hi laura , how can we auto populate user information in newitem(newform.aspx) for the given user id in the list field, my requirement is there are three fields in list,in one field we have to give user id(not current user) rest of fields should be dynamically populate with the user informail like email full name please help,

  • I don’t know, that sounds like it would require custom code. You can accomplish the same thing easily with InfoPath if that is an option for you.

  • Hi Laura, When I click Finish on the “Configure Connection” window, I was route to an error 403 page. Do you know what I was missing? Thank you,

  • I am interested in doing something similar using the User Lookup field in SharePoint. We enter quick support tickets for password resets by looking up the caller in User Lookup. I then want to pass informatino from that lookup to other fields on the New Item form (Name, Email, etc.). Could you provide some information on how to do this?

  • Hi, This looks really good but, we have only standard version,so i can’t see the current user filter obviously, is there anything i can do to get the username of a current user. Thank you.

  • Mei, I’ve never seen it do that, I don’t know. Dave, Are you on SharePoint 2010 enterprise? If so, it’s easy with InfoPath, the people picker and the user profile service. Otherwise I don’t know how it would be done. Anil, There’s a way to add a parameter to a data view web part that uses one of the built in server variables. There’s one called Logon_user, but I don’t think it will be very useful in trying to do what is done in my blog post. http://msdn.microsoft.com/en-us/library/ms524602.aspx

  • I am able to get to the part where I’m supposed to setup a connection but the option to “Get Parameter From” is not available. I only see “Send Filter Values To”.

  • Drew, As long as you did step 4 and saved the page, there will be parameters in your web part.

  • I’m not 100% sure about this, but in my testing I believe I uncovered a bug. I’m using MOSS 2007, and haven’t had a chance to test in SP2010 yet, so I’ll repost if I see this in 2010. The issue that I am seeing is that when you create your new forms, the form fields display as if you were editing in SPD, but this only happens with a specific circumstance and only happens to the edit form. If you have the SITE level publishing feature on, you will see this happen, and it only happens to the edit form. If you have the SITE COLLECTION publishing feature on, then it won’t. I’ve verified that it has to do with that specific site feature, which is unfortunate as we are using a custom publishing template which requires that this feature in activated. Any ideas/workarounds?

  • Hi Erich, No, I’ve never seen this happen, but I’m not surprised. The publishing features have been quite buggy, and in random places.

  • Hi Laura, this worked brilliantly and so easy to do, thanks for a great solution, one question is there anyway to pull this info from a peoplepicker field in MOSS 2007, I have a form that people can find their ‘user’ and then other fields are populated on that users info, thanks again for a great post

  • Hi Laura, thought I would add my work around to the question regarding updating user information by using people picker, as I do not have a public blog and your site helped me before I thought this is the best place to add. This is not the best solution but it works, on the sharepoint site there is the user information list which is stored in the background, this is defaulted as hidden, this list is located in the -catalog folder within the sharepoint designer. I right click and expose this, then I can create a workflow to update list item based on this user information list. I created a column called ‘account’ then I update this column from the ‘peoplepicker’ this sets the item to the ‘account’ name for person e.g na/kmusg (this how ours is stored). I then added another action to update the first name / last name from the ‘user information list’ linking up with the ‘account’, I then hid the user information list and hey presto all worked. Hope I have explained this wel 🙂 Kris

  • Second post from last, you can only use this user information list at the top level site, you cannot use in a workflow on the subsites because it cannot see the list, I’ve tried connecting to the top level library where it is stored but still cannot do anything with it. Do you have any ideas on how to do this?

  • Kris, Cool little workaround! In 2007, you could create an InfoPath form instead of just a list, and with that you’ll be able to add the user information list as a data connection in the form.

  • Hi Laura, thanks for compliment :-), unfortunately info paths is not supported on our sharepoint :-(, shame because I like the look better. However I digress, there is another work around, I have created all of the columns (first name / last name etc.) as people pickers and defaulted their view respectively (first name etc.), then I used the custom workflow with designer to update these columns from the original peoplepicker column, hey presto all fields have been updated. I would then hide all these extra fields in a custom ‘New’ form so users do not get confused. Thanks again for your post because I didnt really appreciate how we can manipulate all these fields 🙂 Kris

  • Kris, I’ve done the workaround with the workflow before, but I found it to be too unreliable. The workflow only functioned correctly about 80% of the time, and then the other times the fields randomly didn’t get updated. Just FYI.

  • Laura, interesting blog. I found this due to searching for “The data source control failed to execute the insert command”. I’m having issues with my custom edit pages giving this error when we click the ‘Ok’ button to save the data to the posts list on a slightly tweaked Blog site. Akilaskk mentions this in his comment but I can’t see any response from you. I’ve reset the workflow on the list (as mentioned in numerous posts) but still getting this error. Any suggestions would be gratefully received.

  • Jim H, blog sites are a completely different animal than any normal lists and pages. I don’t think anything in this article would necessarily apply to a blog site or any of its pages, unfortunately. I’ve never gotten the error that you two mention, so I don’t know how to address it.

  • You are such a cutie

  • Hi Laura
    I have a question something related with people picker and user profiles.

    I have added a new section called “custom properties” and New field called “Role” with string(Multi Value) — property type.

    Values in the ‘Role’ field are: Director, Valuer.
    some users have both values and some users have only one value.

    In Manage user profiles: For some users I have allocated them as director and valuer, some are only valuers and some are only directors.

    ok now… I have created a people picker field in a list, now the requirement is, when the user select the browse icon next to the people picker field and search for the users.,then it should search and give only the people who have the value “Valuer’ in “Role” field( User Profiles).

    I’ve struggling to get this done.

    Any ideas, really appreciatable
    Thanks

  • I posted this question on the video you made about this but then I realized that all the comments were from 2010 and that this was probably the proper place for such questions:

    This worked great for me in a New Form the way you demonstrated. However when I try it in an Edit Form I’m running into problems. Have deduced that this is because the field is not registering as having changed (because it contains the same data – {$User}). If I make a change to the populated data, such as deleting the last letter, it will then save, but if I simply leave it there and save the data does not post to the list. Also even if I remove the entire populated info and retype it, it won’t save if I type exactly what WOULD be populated. Does anyone know how to work around this issue?

  • Ven,
    I don’t know of a way to do this solution with a people picker control, only a text box. You can do it with a people picker in InfoPath, though.

    Mike,
    Sorry, I’ve never done it with an edit form before.

  • Hi Laura,
    Thank you for this nice solution. One question: The ‘New Item’ title dissappears from the form after you finish the steps you showed. I noticed it is the same for your form on the video you posted. You have left with ‘Test List:’ not ‘Test List: New Item’. How can we fix that?

  • The Current User Web Part returns domain\userid for ‘Manager’. How do we convert that into more user friendly ‘Manager Name’ on the form?

  • Ahmet,
    You can try renaming the aspx page itself, or just type the words New Item on the form itself.
    No, there is no pretty way that I know of for displaying the manager name. I’m not a dev, so I usually use InfoPath to accomplish that.

  • Hi Laura!

    Great site!

    I’m tasked to create our eLeave Application in SharePoint Online under E1 package.

    I’ve created 2 custom list, Employee and eleaveTransaction.

    In employee custom list, columns include EmpName, VL Balance, Date of Hire, and Contact No.

    If I add a new item in eLeaveTransaction, it should automatically fetch columns in Employee list based on the login account.

    How do I do these using SP Designer 2013.

    I badly need your input on this and be greatly appreciated.

    Thanks,
    Venus

  • Hey Laura,

    I am having a Multi-Value People Picker field Assigned Task library, and i want to filter the task that are assigned to me.

    Since it is a Multi value people picker and i have applied the current User filter but its not filtering it.

    So kindly suggest some proper way to do that.

    Thanks,
    Chandra Mouli

  • Venus,
    You can probably accomplish this by opening your site using SharePoint Designer 2010, as I wrote about here, and use the same steps in this blog post. http://wonderlaura.com/2012/8/9/hack-data-view-web-parts-in-sharepoint-2013

  • Chandra,
    Not sure what your question has to do with this particular solution, but you can just use a regular list filter, like Assigned To is equal to [Me]

  • I was not able to get it to work on SharePoint 2010. I manually entered “ASP:TextBox” since there is no textbox dropdown selection. Everything looked good, but I was not able to save the data. What tweaks do I need to do? I appreciate your help.

  • Sorry Bill, but I’ve never seen that just not show up as an option. I can’t think of what else to tell you, it’s usually just there. Try from scratch with a different list?

  • Hey Laura, great post and it works fine with the exception of the fields not being displayed in the list. I’m using SharePoint 2013 and Designer 2013. I’m pulling the current user name and email address on my NewForm.aspx. These fields don’t display on the list. How can I fix this? Thanks

  • Hey Laura, great post and it works fine with the exception of the fields not being displayed in the list. I’m using SharePoint 2013 and Designer 2013. I’m pulling the current user name and email address on my NewForm.aspx. These fields don’t display on the list. How can I fix this? Thanks

  • You are awesome. I am new to SharePoint and my manager is testing me all the time. For this post I will say I LOVE YOU!

Leave a Reply