Site icon @WonderLaura

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:

    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.
    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
    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.
    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:
    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. 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).
    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.
    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.
    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

Exit mobile version