How to pass parameters to secondary data connection web service?

L

liz-kma

I am using this syntax in the script.js file to attempt to set the parameters
before requerying a secondary data source:

g_oXmlUsers = XDocument.DataObjects("GetPositions").DOM;
g_oXmlUsers.setProperty("SelectionNamespaces",
'xmlns:tns=\"http://tempuri.org/\"
xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\"');
g_oXmlUsers.selectSingleNode("/dfs:queryFields/tns:GetPositions/tns:firstName").value = "First Name";

But it always returns a null or empty node error message.

Here's the form file for my secondary data source:

<dfs:myFields
xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:tns="http://tempuri.org"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2003-04-22T21:41:07" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<dfs:queryFields>
<tns:GetPositions>
<tns:firstName></tns:firstName>
<tns:lastName></tns:lastName>
<tns:requisitionNumber></tns:requisitionNumber>
</tns:GetPositions>
</dfs:queryFields>
<dfs:dataFields>
<tns:GetPositionsResponse>
<tns:GetPositionsResult>
<NewDataSet>
<Positions>
<PositionID></PositionID>
<PositionName></PositionName>
<EmployeeID></EmployeeID>
<FormattedName></FormattedName>
<RoleID></RoleID>
<RoleName></RoleName>
</Positions>
</NewDataSet>
</tns:GetPositionsResult>
</tns:GetPositionsResponse>
</dfs:dataFields>
</dfs:myFields>

Any thoughts?

Thanks!
 
S

Scott L. Heim [MSFT]

Hi,

Here is sample code I use in the following scenario:

I have a repeating table with 2 fields - both are drop-down lists. The
first drop-down (ddlCustomers) pulls data from my web service automatically
when the form loads so I can get a list of customers. The second drop-down
in my repeating table (ddlOrders) also gets its records from the web
service but that web method takes a parameter (the customerID) so it does
*not* load its data when the form loads.

In the OnAfterChange event of ddlCustomers, I have the following code:

if(eventObj.Operation == "Insert")
{
//Get a reference to the data object
var objOrdersDO = XDocument.DataObjects("GetOrders");

//Load the data objects DOM into a new variable so we can
//set the SelectionNamespaces to be able to navigate the nodes
var objDOM = objOrdersDO.DOM;

//Set the SelectionNamespaces property
objDOM.setProperty("SelectionNamespaces",

'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSoluti
on" ' +
'xmlns:tns="http://tempuri.org/NWTables/Service1"');

//Get a reference to the query field from the web method
var myQueryField =
objOrdersDO.DOM.selectSingleNode("//dfs:myFields/dfs:queryFields/tns:GetOrde
rs/tns:strCustID");

//Set the text of this query field to the selection made from the
ddlCustomers box
myQueryField.text = eventObj.Site.text;

//Execute the query for the GetOrders data connection to retrieve the
records
objOrdersDO.Query();

//Clean up
objOrdersDO = null;
objDOM = null;
myQueryField = null;
}

I hope this helps you!

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

liz-kma

Hi Scott,

Yes, thank you! I had not been able to find a way to correctly reference
the "tns" namespace. The other references I found just pointed to
tempuri.org without the virtual directory.

I also wondered whether there was a way to programmatically update the web
service being used by the secondary datasource, in case the web service path
changes.

-- Liz
 

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