Forms That Query for Data


 CD-ROM     Another use of Web Services and InfoPath is to develop solutions that query data from a Web Service and return the data into a form. This solution type contains two InfoPath forms. The first provides a query view; the second is a data entry form that displays the queried data. Let s extend the Interview Feedback application, because the hiring manager wants to review submitted forms that show the notes entered about a candidate during the interview process. (You can find the Interview Feedback files on the CD-ROM in \Code\Chapter 4\Manager Feedback\RetrieveFeedback.xsn.) The first step in retrieving this information is to extend the current Web Service using the WebMethods Framework to query and retrieve the appropriate data. Based on the defined workflow and database architecture, the applicant name is used as the query mechanism.

Returning the Data Document

The new method added to the Web Service returns an XML data document and not an ADO.NET dataset. InfoPath doesn t provide direct support of the dataset data type; instead, it is designed to work with generic XML payloads. The dataset is serialized using a specific XML format that contains an inline schema. This schema defines the inline payload that the current InfoPath application is unable to process directly. Instead of returning the dataset, this method returns an XML data document, as shown in Listing 4.7.

Listing 4.7: Example of converting a dataset to a format that InfoPath can understand.
start example
 <WebMethod()> Public Function GetApplicantFeedBack(ByVal ApplicantName  As String) As System.xml.XmlDataDocument   'db connection   Dim sqlConn As SqlConnection   Dim sqlCmd As SqlCommand   Dim strConstring As String   Dim intUserID As Integer   strConstring = ConfigurationSettings.AppSettings("constring")   sqlConn = New SqlConnection(strConstring)   sqlConn.Open()   sqlCmd = New SqlCommand   With sqlCmd     .Connection = sqlConn     .CommandTimeout = 30     .CommandType = CommandType.StoredProcedure     .CommandText = "GetFeedbackByApplicant"     .Parameters.Add("@ApplicantName", ApplicantName)   End With   Dim ApplicantDA As SqlDataAdapter = New SqlDataAdapter   ApplicantDA.SelectCommand = sqlCmd   Dim ApplicantDS As DataSet = New DataSet   ApplicantDA.Fill(ApplicantDS, "Evaluator")   ApplicantDS.Namespace = "Http://localhost/Receivefeedback"   Dim Info As System.Xml.XmlDataDocument = New System.Xml.XmlDataDocument(ApplicantDS)   Return Info   sqlConn.Close() End Function 
end example
 

InfoPath is unable to natively track changes to XML data. This is a feature provided by the dataset. This is not an issue within this type of application. However, if this were a requirement within the application, additional code and the InfoPath object model could be used to solve this problem.

The Manager s Views

Using InfoPath, we can create a data source that points to the newly deployed Web Service. For this application, select the Receive Data option for the data source, as shown in Figure 4.21. By default this disables the automatic submit features within InfoPath.

click to expand
Figure 4.21: Selecting Receive Data for the Web Service.

Once the data source is created, InfoPath attempts to retrieve a set of sample data with a query to the Web Service, as shown in Figure 4.22. The sample query enables the data source to retrieve and analyze a specific XML document and to determine the associated fields and controls within the data source.

click to expand
Figure 4.22: Defining sample data for the data source.

Once the data fields are retrieved, the data source is fully initialized . InfoPath defines two default data views. The query view is the default page available when the user opens the InfoPath form. This page provides the initial data capture that is used to retrieve Web Service data and load the Data View page. By default, the data entry view is also created. This view is initially created as a blank page to which form designers can add data source fields that are used to add new records. The initial view and the necessary code to manage view changes is maintained as part of the .xsf file and defined as part of the application manifest. Within the solution file, a script file called internal.js is auto-created ; it contains the script code fired on the return of the Web Service data, shown in Listing 4.8.

Listing 4.8: Events fired when Web Service data is returned.
start example
 // This file is automatically created and modified by Microsoft Office  InfoPath. // Do not modify the contents of this file. function SwitchToView0::OnClick() {   XDocument.View.SwitchView("Retrieve Info"); } function SwitchToView1::OnClick() {   XDocument.View.SwitchView("Manager Lookup"); } 
end example
 

Once the Web Service Adapter returns the data, this event script is called and the results are displayed within the Manager Lookup view.




Programming Microsoft Infopath. A Developers Guide
Programming Microsoft Infopath: A Developers Guide
ISBN: 1584504536
EAN: 2147483647
Year: 2006
Pages: 111
Authors: Thom Robbins

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net