Insert New Row giving validation errors. - InfoPath Dev
in

InfoPath Dev

Insert New Row giving validation errors.

Last post 01-16-2008 03:59 PM by Matt Faus. 14 replies.
Page 1 of 1 (15 items)
Sort Posts: Previous Next
  • 01-14-2008 06:22 AM

    Insert New Row giving validation errors.

    I am programatically inserting a new row in one of my master detail repeating section.  I am using the create node and append child to insert a new row.  However, when the new row is inserted i am getting data validation errors on my date/time fields and my ink picture fields.  Has anyone come across this and know how to fix this?

  • 01-14-2008 07:53 AM In reply to

    Re: Insert New Row giving validation errors.

    If a datetime field is set to blank, you must also add the xsi:nil='true' attribute to it so that the UI will realize that it is purposfully blank.

     My guess is that the ink field is similar.

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 01-14-2008 11:46 AM In reply to

    Re: Insert New Row giving validation errors.

    This is my JScript code:

    var Elem = XDocument.DOM.selectSingleNode("/my:IC3/my:ConsentForms");
    var copyElem = Elem.cloneNode(true);
    var newRepeatRow = XDocument.DOM.createNode(1, "my:ConsentForm", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var newDateRow = XDocument.DOM.createNode(1, "my:ConsentD_T", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var lastRow = Elem.selectNodes("my:ConsentForm").length;

        XDocument.View.DisableAutoUpdate();
       
        newRepeatRow.appendChild(newDateRow);

     

    where would i add in the xsi:nil='true'?  Thank you for your help 

  • 01-14-2008 01:41 PM In reply to

    Re: Insert New Row giving validation errors.

    From looking at your code, I would do this: 

    Use createNode() to create an attribute with the xsi namepsace, set the value to true, and then add it to the newDateRow object.

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 01-15-2008 07:32 AM In reply to

    Re: Insert New Row giving validation errors.

    I added in the attribute and my new code looks like this:

     

    var Elem = XDocument.DOM.selectSingleNode("/my:IC3/my:ConsentForms");
    var copyElem = Elem.cloneNode(true);

    var xmlNil = Elem.ownerDocument.createNode(2, "xsi:nil", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");

    xmlNil.text = "true";


    var newRepeatRow = XDocument.DOM.createNode(1, "my:ConsentForm", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var newDateRow = XDocument.DOM.createNode(1, "my:ConsentD_T", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var lastRow = Elem.selectNodes("my:ConsentForm").length;

        XDocument.View.DisableAutoUpdate();
       
        newRepeatRow.appendChild(newDateRow);

     

    However, it still gives the data validation in those date fields and the ink signature fields.  Do I need to reference that xmlNil variable to the date fields or somethign like that?  Thank you for your help 

  • 01-15-2008 10:58 AM In reply to

    Re: Insert New Row giving validation errors.

    Yes, you need to do something to the effect of:

    newDateRow.Attributes.addNamedItem( xmlNil );

    I'm not sure if this is the exact syntax in JScript.

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 01-15-2008 11:49 AM In reply to

    Re: Insert New Row giving validation errors.

    I added into my code:

      newDateRow.setAttributeNode(xmlNil);

     

    and i tried the .Attributes.addNamedItem

     

    when i run the second it is giving me object doesnt support

    the first one i run and it is looking for the xmlnil in the schema.  Do i need to add an attribute in the schema?
     

  • 01-15-2008 10:29 PM In reply to

    Re: Insert New Row giving validation errors.

    Hi MHudsonJr,

    Do you have InfoPath 2003? If so, take a look at the jscript code that shipped with the samples. You can simply load the samples in the designer and choose save as source code. Then, go to the folder and look at common.js. There should be a routine in there that will show you how to add the nil attribute. Good luck!

    Patrick Halstead
    Project Manager at Qdabra
  • 01-16-2008 05:35 AM In reply to

    Re: Insert New Row giving validation errors.

    I have 2007.  I saw there were a few samples but when I opened all the samples none of them had an insert button associated with them.  Is there one in particular that I should look at? 

  • 01-16-2008 05:50 AM In reply to

    Re: Insert New Row giving validation errors.

    Ok here is my latest:  I added this code:

     

    var oConsentTable = XDocument.DOM.selectSingleNode("/my:IC3/my:ConsentForms");

    var consentRow = XDocument.GetNamedNodeProperty(oConsentTable, "CTRL394", 1); v

    ar consentEnc = XDocument.DOM.selectNodes("/my:IC3/my:ConsentForms/my:ConsentForm");

    var parent = XDocument.DOM.selectSingleNode("/my:IC3/my:ConsentForms");

    var rowOne = parent.selectSingleNode("./my:ConsentForm");

    var rowClone = rowOne.cloneNode(true); parent.insertBefore(rowClone, rowOne); 

     

    This works but as you can see it inserts before, and the insertAfter doesnt work.  Is there a way to insert after using this because that would solve all my problems because their is no validation errors with this insert. 

  • 01-16-2008 07:09 AM In reply to

    Re: Insert New Row giving validation errors.

    Try parent.appendChild( rowClone );

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 01-16-2008 08:10 AM In reply to

    Re: Insert New Row giving validation errors.

    Ok well i guess I didnt do enough testing, and I found out that my latest code is just copying the previous row and not inserting a blank row.  The appendChild did work to insert it after but I need this new row to be a blank row.  Sorry for all the confusion and I really do appreciate your help. 

  • 01-16-2008 08:27 AM In reply to

    Re: Insert New Row giving validation errors.

    It's probably easiest to just set the values of each of the columns to blank:

    rowClone.selectSingleNode( "my:column1" ).text = "";

    Attached is a .js file that includes many helpful functions in JScript.  These were shipped with the IP03 sample forms.

     

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 01-16-2008 11:56 AM In reply to

    Re: Insert New Row giving validation errors.

    Hi,

    I´m really interested in this thread and I´m following the suggestions which are made by now --- but unfortunately I have no luck to solve my problem and I hope that someone can help me...

    I want to programmatically insert new rows in a repeated table. One of the column fields is "Date" type --- but not in every case I want to insert a valid date.

    But the problem is that if I programmatically add new rows in the repeating table all of the date fields don´t pass the built-in validation.

    My code (part of it) looks like:

    Private Sub AddNewRow(ByRef fragment As IXMLDOMDocumentFragment, ByVal strPosKtoNr As String, ByVal strPosSoll As String, ByVal strPosHaben As String, ByVal strPosValuta As String, ByVal strPosGAB As String, ByVal strPosKtoBez As String, ByVal strPosAWG3 As String, ByVal strPosAWG7 As String, ByVal strPosAWG8 As String)

     

    Dim belegPos As IXMLDOMNode = fragment.appendChild(thisXDocument.createNode(DOMNodeType.NODE_ELEMENT, "my:absBuchungsPositionenGrp", XmlNamespace))

    ....... 

    Dim txtBelegPosValuta As IXMLDOMNode = belegPos.appendChild(thisXDocument.createNode(DOMNodeType.NODE_ELEMENT, "my:datBelegPosValuta", XmlNamespace))

    txtBelegPosValuta.attributes.removeNamedItem("xsi:nil")   ''' No success !!!

    txtBelegPosValuta.text = String.Empty

    ..... 

    End Sub

    Can anyone help me to get rid of the "date validation" for the field "datBelegPosValuta"

    I use managed code (VB.Net) and Infopath 2003.

    Thank you very much for any help.

    Regards, Karsten

    Karsten
  • 01-16-2008 03:59 PM In reply to

    Re: Insert New Row giving validation errors.

    Here's how to set the nil attribute in C# on the IP03 OM.  Sorry about the loss of indention. 

     

    public
    void btnClearDate_OnClick(DocActionEvent e)

    {

    IXMLDOMNode dateNode = thisXDocument.DOM.documentElement.selectSingleNode("/my:myFields/my:dateNode");

     

    // This method causes data validation on nodes with a Date field type

    dateNode.text = "";

    // The above generates the following XML. The empty string is not recognized as a valid date.

    // <my:dateNode></my:dateNode>

    // To add a valid "blank" date you must add the xsi:nil='true' attribute

    SetNil(dateNode);

    // The above generates the following XML.

    // <my:dateNode xsi:nil="true"></my:dateNode>

    }

    public void SetNil(IXMLDOMNode Node)

    {

    if (Node == null)

    return;

    IXMLDOMElement oElement = (IXMLDOMElement)Node;if (oElement.getAttribute("xsi:nil") != null)

    {

    // Create xsi:nil attribute with the proper namespace.

    IXMLDOMAttribute oNil = (IXMLDOMAttribute)Node.ownerDocument.createNode((int)DOMNodeType.NODE_ATTRIBUTE, "xsi:nil", "http://www.w3.org/2001/XMLSchema-instance");

    oNil.text = "true";

    // The order is important.

    if (Node.text != "")Node.text = "";

    oElement.setAttributeNode(oNil);

    }

    }

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