Editor's Note: The following MVP Monday post is by SharePoint Server MVP Clayton Cobb.
One of the most powerful features of InfoPath 2010 is the ability to dynamically populate fields in the form with already-known data without input from the user – or with minimal input. With out-of-the-box (OOTB) list forms, we cannot do this, which makes OOTB forms very limiting in their native form. However, once we switch to InfoPath forms,the possibilities increase immensely.
In this article, we will provide a prequel to the article by Laura Rogers named SharePoint Designer Workflow Tasks and InfoPath 2010. In that article, Laura showed us how to display relevant Expense Report data when working with task forms within a SharePoint Designer workflow. In this article, I will show you how to auto-populate data in the original form that the user is filling out to trigger the workflow, and my scenario will be a Leave Request approval system, which is another common process in most organizations.
The following components will be involved in the Leave Request approval solution:
The Leave Request form template containsthe following columns (Fig. 1):
Figure 1 – InfoPath form fields used in the Leave Request form template
Some of these fields get promotedto the form library for display purposes and for usage in the workflow, but others are used strictly within the form for comparison and matching purposeswhile the form is open.
The run-time version of the form template looks like this (Fig. 2):
Figure 2 – InfoPath Leave Request run-time experience
Figure 2 above shows exactly what the user sees upon initially opening a Leave Request. Let’s take a look at all the fields that are visibly auto-populated, and then we’ll show how each one was done:
Let’s start by proving that the first 6 items in the above list really are coming from external data sources (Fig. 3):
Figure 3 – Proof of external data sources
In Figure 3 above, you can see the following items:
In order to retrieve this external data, we need to add the appropriate data connections as seen below (Fig. 4):
Figure 4 – Proof of external data sources
In Figure 4 above, you can see five data connections, but the two key ones for this article are the ones named Leave Days and GetUserProfileByName. I’ve highlighted the Leave Days data connection in this case in order to explain it in detail. You can get an in-depthexplanation of how to set up and use the GetUserProfileByName data connection here: InfoPath - Get user information without writing code (extended).
Notice these details regarding the Leave Days data connection:
Bullet #2 is very important, because this is something you want to always try to do whenever it is possible. I am not querying the data connection on form load, because I want to query theLeave Days list using a known value. If you query automatically on form load, then the resulting data set includes all data from the source. If the source contains hundreds or thousands of items, then your form’s performance will suffer. Instead, we are performing a parameterized query so that the resulting data set only contains the information we need. This can still be done on form load, but it cannot be done dynamically within the data connection settings itself. Instead, we perform the steps shown below (Fig. 5 and 6):
Figure 5 –Action rules that fire after form load, thus starting the auto-population process
Figure 5 above shows the initial actions that take place when the form is first opened. Notice the following details:
Figure 6 – Additional action rules that continue the auto-population process
Figure 6 above shows the next string of actions that auto-populate the rest of the fields in the form:
The resultof this string of steps is that we only retrieve the data for the current/selected user (i.e. Clayton Cobb) instead of the entire data set, and then we auto-populate the most important field – DaysAccrued - with the current user’s actual # of accrued leave days per the master data source. Again, this technique is extremely important to master, because it will streamline your solutions while ensuring the least amount of overheard with your data connections. This technique will allow you to deal with large data sets in an efficient manner while resulting in excellent performance.
Puttingforth the effort on the front-end of your solution so that your form template populates as many fields as possible is highly recommended. Approaching forms in this manner allows your users to spend less time, have less frustration, have fewer mistakes, and have more meaningful interactions with your solutions. Doing this helps transform frustrating paper-based processes into streamlined electronic-based processes.
Clayton is a current Microsoft SharePoint Server MVP and former InfoPath MVP who is very active in the SharePoint community. Clayton has coordinated and led three SharePoint Saturday Denver events and actively co-leads the Colorado SharePoint User Group. Additionally, Clayton has spoken at many conferences and user groups over the last few years in order to share his knowledge and gain new friends who share the same passion for technology.
Clayton has a wife, Ann, and three young children, including twin baby girls. Clayton is an avid fan of the University of Alabama and races his Mitsubishi Evo in his free time (drag, autocross, and circuit).
The MVP Monday Series is created by Melissa Travers. In this series we work to provide readers with a guest post from an MVP every Monday. Melissa is a Community Program Manager for Dynamics, Excel, Office 365, Platforms and SharePoint in the United States. She has been working with MVPs since her early days as Microsoft Exchange Support Engineer when MVPs would answer all the questions in the old newsgroups before she could get to them.
Quick question about the date picker controls. Once a user selects the Start/End date for their leave. How do I publish that information into a Sharepoint list which then calculates the amount of days leave required?
Can you please help me out in configuring Person\Group picker InfoPath 2010.
I need to pre populate email & phone based on the entered user.
when i configure and try to populate the email & phone of the entered person name. i could able to see only the login users email and phone no in the respective fields.