secondary data source...where is my data? - InfoPath Dev
in

InfoPath Dev

secondary data source...where is my data?

Last post 02-24-2006 06:49 AM by Matt Faus. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 02-23-2006 01:40 PM

    • brandt
    • Top 500 Contributor
    • Joined on 02-23-2006
    • USA
    • Posts 26

    secondary data source...where is my data?

    I keep having trouble with this...I cant seem to get a nonNull reference to
    my secondary data...all is well (presumably) until the next to last line of
    code...always returns a null reference...anybody care to debug?
    /*
    * This file contains functions for data validation and form-level events.
    * Because the functions are referenced in the form definition (.xsf) file,
    * it is recommended that you do not modify the name of the function,
    * or the name and number of arguments.
    *
    */

    // The following line is created by Microsoft Office InfoPath to define the
    prefixes
    // for all the known namespaces in the main XML data file.
    // Any modification to the form files made outside of InfoPath
    // will not be automatically updated.
    //<namespacesDefinition>
    XDocument.DOM.setProperty("SelectionNamespaces",
    'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:q="http://schemas.microsoft.com/office/infopath/2003/ado/queryFields"
    xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"
    xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"
    xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-02-21T03:22:17" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
    XDocument.GetDOM( "vwCustomerInfo_basic" ).setProperty(
    "SelectionNamespaces" ,
    'xmlns:d0="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"
    ' );
    //</namespacesDefinition>


    //=======
    // The following function handler is created by Microsoft Office InfoPath.
    // Do not modify the name of the function, or the name and number of
    arguments.
    // This function is associated with the following field or group (XPath):
    /dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustName
    // Note: Information in this comment is not updated after the function
    handler is created.
    //=======
    function msoxd__tblRAHeader_CustName_attr::OnAfterChange(eventObj)
    {
    // Write code here to restore the global state.

    if (eventObj.IsUndoRedo)
    {
    // An undo or redo operation has occurred and the DOM is read-only.
    return;
    }

    // A field change has occurred and the DOM is writable. Write code here to
    respond to the changes.
    // Retrieve the vwCustomerInfo_basic secondary data source

    // Retrieve the SQL statement of the data source
    // (the DOM of the vwCustomerInfo_basic Data Object)

    var customerInfoAuxDom = XDocument.DataObjects("vwCustomerInfo_basic").DOM
    XDocument.UI.Alert(customerInfoAuxDom == null);
    customerInfoAuxDom.setProperty("SelectionNamespaces",
    'xmlns:d0="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"');

    var strSQL =
    XDocument.DataObjects["vwCustomerInfo_basic"].QueryAdapter.Command;
    XDocument.UI.Alert(strSQL);

    var strCustName = eventObj.NewValue;
    XDocument.UI.Alert(eventObj.NewValue);

    // Generate the new SQL statement with WHERE clause
    strSQL += " where vwCustomerInfo_basic.Name = ' " + strCustName + " '";
    XDocument.UI.Alert(strSQL);

    // Populate the command with the new SQL statement
    XDocument.DataObjects["vwCustomerInfo_basic"].QueryAdapter.Command = strSQL;

    // Run the query
    XDocument.DataObjects["vwCustomerInfo_basic"].Query();
    XDocument.UI.Alert("Query has been run");

    // Find the Customer in the secondary data source and the CustomerNum in
    the main data source
    var customerAuxNode = customerInfoAuxDom.selectSingleNode(
    "/d0:myFields/d0:Customer"); <<<<====== returns TRUE-ie null ref displayed by code below...namespace issue?

    XDocument.UI.Alert(customerAuxNode == null);


    var strCustomer = customerAuxNode.text;
    XDocument.UI.Alert(strCustomer);

    // Update the main data source with the queried value;
    // Populate XML document with customer information.


    }
  • 02-23-2006 03:55 PM In reply to

    Re: secondary data source...where is my data?

    I think this is a namespace issue, check out this HowTo, maybe it will help:http://infopathdev.com/howto/tutorials/default.aspx?i=ed2cf0c5895f468995cdd081cf17fead

    You will want to check the namespace of each element, so answer these questions:

    What is the namespace for myFields?
    What about Customer?

    If they are different, you will have to establish another namespace, d1, that references the second namespace.

    I hope this helps!

    By the way, what kind of data connection is this? SharePoint list? Access database? XML file?

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 02-23-2006 07:19 PM In reply to

    • brandt
    • Top 500 Contributor
    • Joined on 02-23-2006
    • USA
    • Posts 26

    Re: secondary data source...where is my data?

    quote:
    Originally posted by MFaus

    I think this is a namespace issue, check out this HowTo, maybe it will help:http://infopathdev.com/howto/tutorials/default.aspx?i=ed2cf0c5895f468995cdd081cf17fead

    You will want to check the namespace of each element, so answer these questions:

    What is the namespace for myFields?
    What about Customer?

    If they are different, you will have to establish another namespace, d1, that references the second namespace.

    I hope this helps!

    By the way, what kind of data connection is this? SharePoint list? Access database? XML file?

    ---------------
    Matt Faus
    InfoPath Dev Texas


  • 02-23-2006 07:47 PM In reply to

    • brandt
    • Top 500 Contributor
    • Joined on 02-23-2006
    • USA
    • Posts 26

    Re: secondary data source...where is my data?

    LOL...thats what I figured...but your article doesnt help me much...you tell me what they should be??? I need this debugged.

    Here is what I get when I follow your advice perhttp://infopathdev.com/howto/tutorials/default.aspx?i=ed2cf0c5895f468995cdd081cf17fead

    vwCustomerInfo_basic (Group)

    Namespace:http://schemas.microsoft.com/office/infopath/2003/ado/dataFields
    Minimum occurrences: 0
    Maximum occurrences: unbounded
    Default value: [none]


    That namespace IS declared...done by IP in the namespaces area...is this the Customer namespace you mentioned?

    I added:
    XDocument.GetDOM( "vwCustomerInfo_basic" ).setProperty(
    "SelectionNamespaces" ,
    'xmlns:d0="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"
    ' );
    to make it reference d0...is this correct?Then I used d0 to try to get to the fields....how can I tell if my query ran successfully and actually has data? Is it possible that my problem is with no data set returned? BTW-I've been researching this for ~10 hrs...got an example using Secondary Data sources from SQL server to do what I am attempting? I can send you screen shots if neccessary.
  • 02-24-2006 12:16 AM In reply to

    Re: secondary data source...where is my data?

    Hi Brandt and welcome to our forum!

    Are you saying that Matt's HowTo needs to be debugged or that you want us to debug your code? If the former, we will investigate. If the latter, we can help, but this is such a common error that if we helped everyone we would be out of business in no time and you would have no forum at all... do you want that? :) :)

    On the other gland, 10 hours is just too long. You should ask for help after 30 minutes max.

    Patrick Halstead [InfoPath MVP]
    InfoPath Dev Seattle
    Patrick Halstead
    Project Manager at Qdabra
  • 02-24-2006 05:20 AM In reply to

    • brandt
    • Top 500 Contributor
    • Joined on 02-23-2006
    • USA
    • Posts 26

    Re: secondary data source...where is my data?

    It's definitely with my code...I appreciate your time management requirements...but , yes-I wish you would debug my code...just this once...I'm sure there are others out there with the same problem...it's frustrating not to find concise examples on how to do this...but I have followed all the advice trails and just dont seem to be able to hook into my query data...

    I'm confused, on one front, about the need to add the namespace for secondary data...it appears to me to be already in the default code???
  • 02-24-2006 06:49 AM In reply to

    Re: secondary data source...where is my data?

    Hi Brandt,

    I'm sorry that the HowTo was not easily understood, I will look into making things more clear.

    It seems that you correctly identified the namespace on the group, but remember each node in the hierarchy can contain a different namespace.

    From your example above, I think something besides namespace issues is going on here and to confirm this I would like you to provide the following screenshots:

    Open the Data Source task pane, select Main from the data source drop-down. Expand all folders (if it is too many to fit on one screen, just expand the relevant ones). Screenshot the Data Source task pane.

    Repeat for all secondary data sources.

    Again, I'm sorry the HowTo did not help, but after providing those screenshots I think I will be able to make things crystal clear. I know where you're coming from, the first day I started writing code in InfoPath it took me FOREVER to figure out how to actually run queries, but after you figure that little thing out you will be set.

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.