InfoPath's JScript and web service

F

forum7

I have an InfoPath form that contains an Employee ID, First Name
(read-only) and Last Name (read-only) fields. These fields map to a SQL
Server database table containing employeeID, firstName and lastName
fields respectively. When the user types in an Employee ID number, an
onAfterChange() event is treated by the form's JScript code, which must
call a web service (secondary data connection) method that takes in an
input String argument of employeeID and outputs the following XML:
<?xml version="1.0" encoding="utf-8" ?>
<empDS>
<Employees>
<lastName>Aldrin</lastName>
<firstName>Edward</firstName>
</Employees>
</empDS>
So, the JScript must receive this XmlNode (return type of web service
method), extract the firstName and lastName values and populate the
InfoPath form's First Name and Last Name fields respectively.
I am able to call the web service from the JScript, but am having
problems with the extraction and population of the first name and last
name for the input employee ID. Below is the relevant part of the
JScript code.
-------------------BEGIN CODE------------------
var employeeID =
XDocument.DOM.selectSingleNode("//my:EmployeeID").text;

var employeeInfoWS = XDocument.GetDOM("GetEmployeeInfo");
employeeInfoWS.setProperty("SelectionNamespaces",
"xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\"
xmlns:s0=\"http://tempuri.org/\"");
//Set Web Service parameters
employeeInfoWS.selectSingleNode("/dfs:myFields/dfs:queryFields/s0:GetEmployeeInfo/s0:employeeID").text
= employeeID;
// Perform the query via the web service
XDocument.DataObjects("GetEmployeeInfo").Query();
// Get value of lastName from the XML of the web service response
var employeeNode =
employeeInfoWS.selectSingleNode("/dfs:myFields/dfs:dataFields/s0:GetEmployeeInfoResponse/s0:GetEmployeeInfoResult");

try
{
//var lastNameNode =
employeeNode.selectSingleNode("/s0:empDS/s0:Employees/s0:lastName").text;
XDocument.DOM.selectSingleNode("//my:LastName").text =
employeeInfoWS.selectSingleNode("/dfs:myFields/dfs:dataFields/s0:GetEmployeeInfoResponse/s0:GetEmployeeInfoResult/s0:NewDataSet/s0:Table/s0:lastName").text;
}
catch (e)
{
XDocument.DOM.selectSingleNode("//my:LastName").text = e.message;
}
--------------------END CODE-------------------
An exception is being thrown when I try to access the <lastName> node
and its text value. However, if I traverse only upto
GetEmployeeInfoResult with the following XPath with the following code:

-------------------BEGIN CODE------------------
XDocument.DOM.selectSingleNode("//my:LastName").text =
employeeInfoWS.selectSingleNode("/dfs:myFields/dfs:dataFields/s0:GetEmployeeInfoResponse/s0:GetEmployeeInfoResult").text
--------------------END CODE-------------------
I see "AlrinEdward" populated in the form's Last Name field. So I know
the web service is able to return the relevant data just fine. From the
web service method's code, I am returning an XmlNode data type, so I am
not sure why the JScript is unable to traverse beyond
GetEmployeeInfoResults, which contains the XML response. FYI, the XML
response is structure as below:

-------------------BEGIN CODE------------------
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetEmployeeInfoResponse xmlns="http://tempuri.org/">
<GetEmployeeInfoResult>xml</GetEmployeeInfoResult>
</GetEmployeeInfoResponse>
</soap:Body>
</soap:Envelope>
--------------------END CODE-------------------
This thread is still alive on the InfoPathDev site @
http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=283

Any input is highly appreciated. Thanks!

--webuser
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top