Monday, December 10, 2012

PrePopulate SharePoint List Form Data (On Line Version) - Part 1

One recent project had a requirement where when a new list item was created, several pieces of information needed to be populated based on the logged in user (this is for SharePoint Online in Office 365). There are several great articles dealing with this utilizing InfoPath (credit here to Laura Rogers at http://www.wonderlaura.com). However there is a way to accomplish this without having to create an InfoPath Library and just using a SharePoint list (my approach is to stay simple until I absolutely have to make things more complex).

The first thing to create is the source list. Meaning the list that ties the user account to the data I wish to prepopulate in my list. Create a SharePoint Custom list (in my example titled: Source List) with the following columns:  Department column (single line of text), and then a Users column which is a Person or Group column. (Please note for the Show field option at the bottom of the Person or Group column, select Account- this is specifically for Office 365 SharePoint):





Now, it is time to create the list that this information will be supplied to. Just for an example, I will create a list titled Comments with the following columns: Submitter Name (single line of text), Department (lookup to the Source list created above utilizing the department column) and Comments (mulitiple lines of text):




From the Ribbon bar at the top, select the List tab:








Select Customize Form in the Customize List section (Please note for this feature to be enabled, InfoPath Designer 2010 must be installed on the computer) :










InfoPath Designer 2010 will open the form for the Comments list.

The first thing needed is to prepopulate the Sumitter Name column with the Account Name from the logged in user. There are several ways to approach this and one of the simplest (because I like simple) is to set the default value of the Submitter Name column from a Form Load Rule.

On the Ribbon Bar in InfoPath, select the Data tab:








Then select Form Load in the Rules section:









Under the Form Load Rules, select the New drop down and then select Action:











Enter text to the Details for column (in this example I entered PopulateSubmitterName to remind me of the purpose of this rule):








Leave the Condition as the default and Rule type is Action. Select the Add drop down and select set a Field's value:




















The Rule Details screen will appear. Leave Action set to Set a field's value. For the Field selection, select the icon on the right




and select the name of the field to pre-populate - in this case Submitter Name.
























For the Value selection, select the fx icon on the right hand side





On the Insert formula screen, select Insert Function:






















Select Insert Function:





















For Categories, select User and then for Functions select userName and select Ok 3 times:
























Finally, Quick Publish the new form to the list by selecting the icon at the top of the page:







Now when the form loads, the User Name is displayed:











A couple of things to keep in mind. The User name is a little different than on premise as I am using an Office 365 setup for this demonstration - which limits how an account can be pulled into the form some.

Also, a condition may need to be set so that the submitter name is only entered if the field is blank.

In part 2 of this series, I wall through populating the Department name based on the Source list where we tied the username to an actual Department.

2 comments:

Stéphane Bazin said...

Great post-Thanks
But... I was looking for the "part " purpose
Stéphane (Paris, France)

Samurai said...

Perfect. This was what exactly I was looking for.