DeleteSelf() method does not trigger on an InfoPath Form - InfoPath Dev
in

InfoPath Dev

DeleteSelf() method does not trigger on an InfoPath Form

Last post 07-13-2011 02:29 AM by Jimmy. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-12-2011 09:38 AM

    DeleteSelf() method does not trigger on an InfoPath Form

    I am trying to trigger a WF on an InfoPath form to delete a row from a Repeating Table within the form, when a certain condition is met. The DeleteSelf() method does not throw any error/Exception, but does not execute as well. When I view the form after the WF completes (no exceptions again), all the rows in the repeating table are still there. Note: The WF is being manually started, for testing purposes. Am I missing something here? Here is the code: ************************************************************************************************** XmlDocument xml = new XmlDocument(); using (Stream s = workflowProperties.Item.File.OpenBinaryStream()) { xml.Load(s); } XmlNamespaceManager man = new XmlNamespaceManager(xml.NameTable); man.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); man.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml"); man.AddNamespace("xd", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-09T15:29:07"); man.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-09T15:29:07"); root = xml.CreateNavigator(); XPathNodeIterator iter = root.Select("/my:myFields/my:grpRequest", man); int nodesCount = iter.Count; string app = GetSubstring(workflowProperties.Item["Title"].ToString(), "_", ".xml"); for (int i = 1; i
  • 07-12-2011 11:29 AM In reply to

    Re: DeleteSelf() method does not trigger on an InfoPath Form

    Looks like your code was cut off.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-12-2011 12:01 PM In reply to

    Re: DeleteSelf() method does not trigger on an InfoPath Form

    Here is the full code:

    XmlDocument xml = new XmlDocument();

    using (Stream s = workflowProperties.Item.File.OpenBinaryStream())
    {
    xml.Load(s);
    }

    XmlNamespaceManager man = new XmlNamespaceManager(xml.NameTable);
    man.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    man.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml");
    man.AddNamespace("xd", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-09T15:29:07");
    man.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-09T15:29:07");

    root = xml.CreateNavigator();

    XPathNodeIterator iter = root.Select("/my:myFields/my:grpRequest", man);
    int nodesCount = iter.Count;

    string app = GetSubstring(workflowProperties.Item["Title"].ToString(), "_", ".xml");

    for (int i = 1; i (lessthanequals) nodesCount; i++) --- The sematics for "lessthanequals" cannot be used in a post here
    {
    XPathNavigator currentNodeItem = root.SelectSingleNode("/my:myFields/my:grpRequest[" + i + "]/my:strApplication", man);
    XPathNavigator currentNodeItem1 = root.SelectSingleNode("/my:myFields/my:grpRequest[" + i + "]", man);
    if (currentNodeItem1 != null)
    {
    string appName = currentNodeItem.Value;
    string tet = currentNodeItem1.Value;
    if (appName != app)
    {
    currentNodeItem1.DeleteSelf();
    }
    }
    }
    workflowProperties.Item.SystemUpdate(false);
  • 07-13-2011 02:29 AM In reply to

    Re: DeleteSelf() method does not trigger on an InfoPath Form

    There is a semantic problem with your code.  As you iterate through and delete nodes, their positions will change, and the node that was previously at position [2] will now be at position [1] and you will skip over it.

     The typical way to approach deleting nodes is to add all the ones you want to delete to an array, then iterate throught the array and call DeleteSelf() on them.

     I also suggest walking through your code to figure out just what is going on, and it also looks like you're never setting the modified XML back to your list item at any point.

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