Thursday, October 04, 2007

Use Data Connection in InfoPath 2003

Recently, I was asked to work on an InfoPath form project. The form can be opened from a SharePoint intranet site. The form contains several parts to be filled by different people. The person who fills the form can select the next person from company's employee list to fill the next part. If the next person approves the application form, he/she will continue to fill the form and select another person for approval or to fill. If he/she rejects the form, the previous person will be notified.

I used a Drop-Down List Box control for selecting an employee. The DDL box is filled with employees by using a web service (RetrievingAllEmployees method). I set the binding Value to @Email (property of employee), and Display Name to @FullName. However, the problem is that I cannot use the selected employee full name (displayed in the DDLB) in the next part, for example, a Text Box, because the Value of DDLB is an email address.

I realized that in the same web service, there is a method called as RetrieveEmployeeByNetworkUserName, which takes NetworkUserName as an parameter to get an employee object back. I tried to add this as an Data Connection to the InfoPath form, but I did not know how to use, or how to set its parameter.

InfoPath is new for me. There are not much information available on the Web. I tried to post several help questions to Microsoft InfoPath Forum, but no answer yet.

After several hour tries and tests, I finally found a way to solve the problem, using this web service method with parameter as a Data connection. Basically, this data connection has two sets of data (through InfoPath GUI):


  • query fields which are mapped to methods parameters, ie, NetworkUserName, and

  • data fields as properties of returned object, ie, employee.

Base on this information, I figured out that I can use this connection dynamically with the DDLB's Rules (when an item is changed). I added a Rule to the DDLB with the following actions:

  • Set DDLB's value to the data connection's query field NetworkUserName,

  • Use Query Data Connection action with the data connection,

  • Set the data connection's @FullName property value to a text box, and

  • Set the data connection's @Email property value to another text box.

Whalla! This works perfectly. Of course, I changed the DDLB's binding Value to NetworkUser. By using the data connection with parameters, I can let use to specify an employee, and then the employee's information can be obtained easily!

2 comments:

Unknown said...

Hi,
I was trying to use info path to design a form and a print button to the form.I wanted to validate the form fields DDLs and text box and check if they are null and then print when the button is clicked. I tried my best to retrieve the data in the ddls but no vain .Can you help ?

茶樹油客 said...

I am not sure about your question and your case. Let me try to give you a suggestion. First add a field and text control to your form next to the DDLB. Set this field as hidden (see my recent post). Then set a Rule for this DDLB as set the value of this hidden field to DDLB. This will set the text box with the value when DDLB is set. Since the hidden field is not visible, it can only be set when DDLB is changed. I think it is very easy to verify if this field is empty or not as a condition to enable your button.