Enhance InfoPath form with Validation, Formatting and Lookups I am starting with this form here, this InfoPath form, which was just recently converted from a word document. Let me show you the word document quickly. It is called the Resource Provisioning Form and looks very similar to the InfoPath form that I just showed. The dash lines have been converted into text boxes, the brackets with one space have been converted into check boxes, and the check box controls, form field controls have also been converted into check boxes in the InfoPath form, the Application Name table has been converted into a repeating table and these dash lines for notes have been converted into a rich text area, so all that stuff has been done. What I want to do now is to manipulate these fields that have been imported to make them the way I want them to look and to have them behave the way that I wanted to behave. So for example, the name field should be a required field, the date field should be listed as date and it should be read only afterwards and many things like that I would like to do with the form to make it consumable by a person and be efficient for use. Okay, so first I am going to double click on the Name field, and easy as this, clicking on Cannot be blank makes it a required field. Great! For the Date, I want this Date field to not be a text box the way it is right now, I would like it to be a Date Picker Control, which InfoPath provides to me. So, I am going to right click on this field, click on Change To, and pick the Date Picker field, just like that this has been converted into a Date Picker Control now. Same thing I want to do for the Date of Hire, right click, Change To, Date Picker, alright. For the Date field, I want this to display today s date and I want this to not be changeable by the user, so I will double click on this, and first of all let me change this data type to Date. It should not be a text. And now for the default value, click on f x then Insert Function, and I want to choose the today function which returns the current system date. Great, click on Apply. Now I want this to be a Read only field so nobody can change it. Usually, if the readonly option is available, it is displayed in one of these tabs, but there is no Read only option here, so I need to use a work
round to make this field Read only. I want to use what is Conditional Formatting, I will Add a condition. If the Date, which is this field is not blank and which it is not going to be ever because it is populating the today s date in the Date field, so this condition will always return true, so I am going to say that when this is true make this field Read only, OK, OK and OK. Now, for this Date of Hire field, I want this date to never be after today s date, so this Date of Hire field should never be greater than the Date field. Let me double click on this field, and put a Data Validation rule in there. Add Date of Hire if it is greater than, then let us pick the Date field, which is right here. If the Date of Hire is ever greater than Date, put up a ScreenTip saying that Invalid Date of Hire, the Date of Hire cannot be greater than today s date, and I will have a Show dialog box message if this is true, click OK, click OK and I believe that is it. Let me go ahead and change the Data Type also to Date, and that should do it. The next thing is I would like these checkboxes to not be checkboxes anymore, I want them to be radio buttons. So when somebody is filling out this form, they can only select one department and not all three or two of them. So to do that, I need to click on all three, and I am going to push the Ctrl key down and select all three fields, and then right click on them Change To Option Button. Alright, it is as simple as that, and it has changed this to an Option Button group, but now it has named the group Field3, as I hover over, they will all show the exact same name because that is exactly what it is. This is one field with three different options. I can click on any of these radio buttons and it shows me the field name as Field3. Let me go ahead and change that to Department. And as it says, because I clicked on the Sales Department, it shows me that the value is going to be Sales when this radio button is selected. Click OK, and just to verify I will hover over the other ones, and here we go, everything has been changed to Department. Okay now, what I want to do is whenever I select on either of these Departments Sales, IT or HR I want the Department Head to automatically be populated. Well, it has to get the data from somewhere and that somewhere is going to be the Human Resources Site on SharePoint. I want to click on the Department Heads List, which shows all the different Departments Sales, HR and
IT, and the Department Head for each department. So the names Sales, HR, and IT are under the Department column heading while the Department Heads are under the Department Head column heading. Okay so keeping that in mind, what I am going to do first is make a connection. Tools Data Connections Add Create a New Connection to Receive Data, and we are receiving from a SharePoint Library or List. Let us take the URL for this site, copy on the clipboard and put it in the InfoPath Next, and authenticate with my name, okay Department Heads is the list that I want to get the information from. So I will click on Next. And here is all the different fields that I can bring in. I will go ahead and bring in these default fields Department, Department Head, Head Email, Resource Manager, and Manager Email click on Next Next, and it is naming, this connection I am making it is naming it Department Heads, which is fine with me Close. Now, every time this selection changes, I want the Department Head text box to change as well. So, I will double click on this Department radio button, click on Rules, which says The rules apply, the actions get applied every time the value in this controls change. So I will click on Rules and Add a new rule. Action for this rule is going to be to Set a field s value. The fields that I want to select, I will select this, the field is going to be Department Head in the form, and what I want to set it to is actually coming from the secondary data connection to the SharePoint list. Let me click on the f x button, click on Insert Field or Group, and right now the data source is Main, which is the form data source, I am going to change this data source to be Department Heads, which is the secondary data source pointing to the SharePoint list, and I will expand these nodes here to find the field that I am looking for, which is the Department Head field. Now, I need to of course bring back the Department Head, but not any Department Head, I need to bring back the Department Head, which corresponds to the Department that was selected in the form. So while I have this Department Head selected here, I am going to click on Filter Data, and then Add a Filter, and the Filter is going to say that When the Department in the secondary data source of a SharePoint list is equal to, and let us Select a Field or Group, and go back to Main data source and the Department field in the form, which happens to be this one right here. Okay, so when the Department of the secondary data source is equal to the Department in this primary data source, which happens to be the form, bring me back that Department Head name, and populate that in this field, that
is what I am saying. So I am clicking OK to get out of here, lots of clicking OKs, alright done here. Let us look at the bottom to see if there is anything else that needs to be done. Now, the equipment, that is fine, I am just going to leave those as checkboxes. Application Name looks okay as well. Now, the name of the text box might need to be changed to Application Name instead of the Field1, so let me double click on that, and type in Application Name here. Also the Notes field at the bottom, this is named Field 2, I am going to go ahead and rename that to Notes. Great, okay so, now that is all set and done, I am going to go ahead and check this form to make sure it is working properly, click on preview, let us see if we can connect over here, Yes, and this is just asking me if it is ok for this form to go through the SharePoint list to go to the data? and I just said, yes it is fine. Okay so, Name field is, it just cannot be blank, meaning that it is a mandatory field, the required field, I have to fill in something, so fill in my name; Email I can fill something in as well; Date is Read Only, so if I click on the Date picker here, it does not do anything, and I can t type anything in there; Date of Hire, if I try to put in a date that is after today, it gives me a dialogue box saying that Invalid Date of Hire, Date of Hire cannot be greater than today s date, great, let me go ahead and choose something before today; for the Department Head let me click on Sales Department and there we go, it brings back Brandon Olson, IT brings back Greg Lloyd, HR brings back Marty Hester, now all these things are coming up of course from the SharePoint list. One thing that I could also do is not let the user change this name, so right now they are being able to edit the Department Head field, I want this to be read only field so I want to click on Close Preview, go to the Department Head, double click on this text box, the Display tab here does have a readonly checkbox, so as simple as that. Just to make sure, let us click on Preview, and now I cannot type into Department Head field, but it is fillable using these options Sales, IT or HR. Great! Now one other thing that I think would be really cool is if I can fill in the Email field directly, so I do not have to ask the person for their Email, I can just fill in the Email field and maybe other fields as well. But let us focus on the Email field for right now. If I can take the user who signed in, look up their E mail, and be able to fill that in directly, so E mails
and other information is located in Active Directory, of course, in every organization. From Active Directory, it gets imported into the profile database of SharePoint, I can use this form to get to the profile database and get the E mail for this person, whoever signed in, and populate that here. So I will click on Close Preview. The way to do that is through a web service. There is lots of web service that come out of the box with SharePoint and I am going to show you how you can look at the web services here. So Start Administrative Tools Internet Information Services Manager, so here Internet Information Services also known as IIS. I am going to click on SERVER 1 click on Web Sites and go down to the site that I am working with right now, which is Adventure Works that is the portal that I am working with _vti_folder. I have all my web services right here. Now, the way to spot a web service is to look at the extension of this file, if there is an asmx file, this one, this one, this one, all these are web services, so the one that I am looking for actually is called userprofileservice, right here, I want to connect to this userprofileservice in order to get my E mail for the user. Okay, so I will come back to my InfoPath form. Let us make a new connection, Tools Data Connections Add, this time I am making connection to Receive Data, receiving it from a web service and the web service happens to be the http://portal.awbikes.local_vti_bin and here we go, actually it is showing up here in the selection box, so http://portal.awbikes.local_vti_bin/userprofile.asmx is what I want to point to. Click on Next, so these are all the different methods, which are in this web service. I can choose any method to bring back whatever kind of data that I want. I want to use the GetUserProfileByName method where I can pass the person s account name, which is the one that the person is signed in with and it returns back all the different name value pairs of all different fields for this user. So their First Name, Last Name, Account Name, E mail, Phone and everything else. Click on Next. So, it is telling me that it is looking for the Account Name parameter and I do not need to set it right now because automatically it is going to pick it up when my form opens up Next Next, it is going to name this GetUserProfileByName data connection, that is fine with me Finish Close.
Now I want to see exactly what is being brought back. So, I am going to go first of all click on View Task Pane, here is my Task Pane that I need, I go to Design Tasks go to Data Source, and here if I change the Data Source from Main to GetUserProfileByName (Secondary) Data Source, it shows me that under datafields, going down expanding three different nodes here, it brings me name and subsequent value pairs for lots of different fields. Now, it is difficult to determine exactly what that means looking at this node over here, so I am going to take this whole thing over here, the property data and drag it on to the page temporarily just to see exactly how this looks. When I drag it and let it go, it asks me that do you want to put this in as a Repeating Table or Repeating Section or what, so I will do it as a Repeating Table, okay. The columns that I am interested in are Name and Values, so let me go ahead and make them bigger. Make this text box bigger as well. Alright, so I want to see the name and the subsequent value for each different property that is being returned. As a repeating table that is going to be rendered at run time, not at design time, which is what I am in right now, so I am going to run it by clicking on Preview, then click on Yes here for connecting to the SharePoint list and the web service out there. Alright, let us see how it looks, here we go, so once again it is bringing back the name and value pairs, so the account name the value pair for that is awbikes/asif. FirstName value is Asif, Last Name is Rehmani. Now I am looking for the E mail, Workphone, Office, Department, lots of different values that is bringing back. Okay, so here is the name value pair for work E mail, but I am seeing that there is no value, there is no Work Email or E mail for me in the Active Directory database right now, so it is going to bring back no, nothing. So, what I want to do is, let us see, let us test it out to make sure it is going to bring something back. I will log in as a different user who does have a value for the Work Email, and see exactly what they see. Let me go ahead and close this preview and close the InfoPath form, save it. I will save it just the way it is. Now I will go in and I am going to remote desktop as Ben. Ben is another user who does happen to have a Work Email in the Active Directory. Okay so Ben is signed in right now, so let me go ahead and open up Windows Explorer and then navigate to my documents. These were documents that belonged to me, so it is going to be under C\Documents and Settings\Asif and then under
Asif s documents and Word Excel, okay so here it is. Resource Provisioning Form_tables is the one. Let us right click and click on Design, so it opens up the form. Now I want to see the preview of this form, click on Preview, okay click on Yes. As Ben is signed in right now, it is showing the values for Ben, Ben Burton, Preferred Name being Ben Burton together, and all the way down let us look at the Work Email, the Work Email is listed as ben@awbikes.local and that is coming from Active Directory to profile database, and it is being brought in from profile database here. Okay, so let us just stay signed in as Ben Burton and change this and configure this Email text box to pull that Work Email. So double click on the Email and for the default value, I am going to click on the f x and say that, click on Insert Field or Group and the field that I am interested in is the secondary data connection for GetUserProfileByName, under datafields, here it is, value is what I am looking for, so I am looking for the value, which is going to be the Email and since it is a name value pair the name at that time is going to be Work Email, so under the Work Email name, it is going to show me the value which is ben@awbikes.local. So I need to filter on name, let us click on Filter Data Add and filter on name right here, when name is equal to and I am going to type in text over here, and that is going to be Work Email, that is the parameter that I am looking for, Work Email. Click OK and OK, OK, OK, and OK. Now let us see how this works. So I will click on Preview. Here we go. The Email field now shows ben@awbikes.local. Alright, so that is how I was able to get all the information from Active Directory, take the Email field and populate that into this text box. And I could have done the exact same thing for Name and for other values as well if I wanted to, but currently the way we have it configured is all these different text boxes and checkboxes and all of them have different validation and conditional formatting and lookup set on it, so it is just a more productive and efficient use of this form that has been created. So one last thing I am going to go ahead and sign out of here. Let us save this form, log off, and I will still be logged in as myself, which is Asif. I am going to go to My Documents, open up the Resource Provisioning Form_tabes.xsn in Design mode, and make sure that when I do a preview here, it should show me nothing actually for the Email because Asif does not have an Email in the Active Directory. And just to perform some cleanup, click on Close Preview and do not forget to take
out this table, we do not need this table anymore, this was just for temporary basis. So let us go ahead and select that and take it out. And that is how you can make a fully functional form InfoPath form, which has been converted from a Word document.