Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / September 2005

Tip: Looking for answers? Try searching our database.

How to pass parameters to secondary data connection web service?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
liz-kma - 29 Aug 2005 16:31 GMT
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!
Scott L. Heim [MSFT] - 30 Aug 2005 13:22 GMT
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
liz-kma - 31 Aug 2005 13:38 GMT
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

> Hi,
>
[quoted text clipped - 50 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights
Scott L. Heim [MSFT] - 01 Sep 2005 15:07 GMT
Hi Liz,

Yes - you can change the web service using code - it is a little involved.
Take a look at the following post:

http://groups.google.com/group/microsoft.public.infopath/browse_thread/threa
d/82d86a335e866076/faa8f953f1f34565?lnk=st&q=infopath+%22web+service%22+chan
ge&rnum=8&hl=en#faa8f953f1f34565

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights
liz-kma - 01 Sep 2005 17:23 GMT
Hi Scott,

Very helpful and quite easy!  I altered it a bit for web services:

var objWSAdapter;
objWSAdapter = XDocument.DataObjects("MySecondaryDataSource").QueryAdapter;
var tmpXmlDoc = new ActiveXObject("msxml2.domdocument.5.0");
tmpXmlDoc.setProperty("SelectionNamespaces","xmlns:xsf='http://schemas.microsoft.com/office/infopath/2003/solutionDefinition'");
tmpXmlDoc.loadXML(objWSAdapter.Operation);
XDocument.UI.Alert(objWSAdapter.Operation);
var serviceUrlNode =
tmpXmlDoc.documentElement.selectSingleNode("@serviceUrl");
XDocument.UI.Alert("Before: " + serviceUrlNode.text);
serviceUrlNode.text = "http://newwebservicepath/";
XDocument.UI.Alert("After: " + serviceUrlNode.text);
// Save your changes!
objWSAdapter.Operation = tmpXmlDoc.xml;

-- Liz

> Hi Liz,
>
[quoted text clipped - 9 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights
Scott L. Heim [MSFT] - 01 Sep 2005 18:43 GMT
Liz,

Excellent! Thank you for the update.

Take care,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.