Copying secondary datasource to main datasource - InfoPath Dev
in

InfoPath Dev

Copying secondary datasource to main datasource

Last post 08-03-2010 07:18 AM by Jimmy. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 08-02-2010 04:42 AM

    Copying secondary datasource to main datasource

    On form load I am copying a nodeset from a 2ndary source into the main source.  It all works fine except with a dateTime field that is blank, then I get a validation error "only date and time allowed".  Neither of the data sources fields are set to "Cannot be blank".  When I save the xml and view it, the field is an empty element: <my:DateTo/>. I don't see what is wrong with this.

    Any idea what I can do to get this working?

    I am actually not even usign this field in the main data source but it seems that in order to do the copy, the schema must match the 2ndary source exactly wlse I get the error "Schema validation found non-data type errors"

    Filed under:
  • 08-02-2010 05:12 AM In reply to

    Re: Copying secondary datasource to main datasource

    Most likely you will need to add code to add an xsi:nil="true" attribute to your my:DateTo nodes if they are blank.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 08-02-2010 05:55 AM In reply to

    Re: Copying secondary datasource to main datasource

    OK, I found some example of yours in the forum and added this code just after copying the datasource to Main:

        XPathNavigator dateNode = xNavMainDataSource.SelectSingleNode("/my:myFields/my:Meetings/my:Meeting/my:DateTo", NamespaceManager);

        dateNode.CreateAttribute("xsi", "nil", NamespaceManager.LookupNamespace("xsi"), "true");

    But that only adds the attribute to the first record in my repeating group. How do I add it to all records (Meetings)?

    UPDATE:

    I also notice in this post that you said the node must be blank before adding the nil attribute. That will defeat my whole purpose of copying the values from a 2nd data source. Is there a way around this?

  • 08-03-2010 12:18 AM In reply to

    Re: Copying secondary datasource to main datasource

    I'm still struggling with this and would appreciate any help. Thanks.

  • 08-03-2010 02:34 AM In reply to

    Re: Copying secondary datasource to main datasource

    Could you post the code you're using to copy the data over?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 08-03-2010 03:00 AM In reply to

    Re: Copying secondary datasource to main datasource

    See attached. I'm using some xslt code that I found in one of your forums. The code that adds the nil attribute only adds it to the first Meeting record.

    BTW, what does xsi:nil actually do? Is it simply telling Infopath that null values are allowed? Or that the value must be null?

  • 08-03-2010 04:16 AM In reply to

    Re: Copying secondary datasource to main datasource

    OK, I did some homework. Now I realise xsi:nil means the element MUST be empty. So I've added some xslt and my code works fine now.  Here is the xslt - it adds the "my" namespace and adds xsi:nil to my two date fields if they are blank.

    String xsltString = @"<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>

    <xsl:template match='*'>

      <xsl:element name='my:{local-name()}' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-07-28T07:33:11' >

        <xsl:if test='(local-name()=""DateTo"" or local-name()=""DateFrom"") and .=""""'>

          <xsl:attribute name='xsi:nil'>

            <xsl:value-of select='true()'/>

          </xsl:attribute>

        </xsl:if>

      <xsl:apply-templates />

    </xsl:element>

    </xsl:template>

    </xsl:stylesheet>";

  • 08-03-2010 07:18 AM In reply to

    Re: Copying secondary datasource to main datasource

    Excellent!  Glad to hear you figured it out.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.