repeating table add rows programaticly - InfoPath Dev
in

InfoPath Dev

repeating table add rows programaticly

Last post 07-19-2016 05:32 AM by mloftus. 39 replies.
Page 3 of 3 (40 items) < Previous 1 2 3
Sort Posts: Previous Next
  • 11-10-2008 10:11 PM In reply to

    Re: repeating table add rows programaticly

    Hi, 

    “PATH OF THE FOLDER INSIDE REPEATING TABLE FOLDER” means the row (group) inside the repeating table where you want to insert new row (group) before that. (Ex: MainDataSource.CreateNavigator ().SelectSingleNode(“/my:myFields/my:group1/my:group2[my:field1= “Some Value”]”).

    Please follow the below code lines for adding a row inside a repeating table.

    IXMLDOMNode startNode; // Position of the already existing node (row) inside a repeating table.

     IXMLDOMNode newNode; // New node which you want to add inside a repeating table.

    AddWhere  where;// the position of the row.

                    if(where == AddWhere.First)

                    startNode.insertBefore(newNode, GetNode(startNode, "child::node()"));

                    else if(where == AddWhere.Before)

                    startNode.parentNode.insertBefore(newNode, startNode);

                    else if(where == AddWhere.After)

                    startNode.parentNode.insertBefore(newNode, GetNode(startNode, "following-sibling::node()"));

                    else if(where == AddWhere.Last)

                    startNode.appendChild(newNode);

     

    Chandrakanth/GGKTech
  • 11-11-2008 07:00 AM In reply to

    Re: repeating table add rows programaticly

    Hi Hilary,

    I did not have the [Last()] in my XPath so I added that.  The issue I am still seeing is that when I set the value, it sets all the rows values to the new value, not just the new row:

    XPathNavigator group = MainDataSource.CreateNavigator().SelectSingleNode("/my:ProjectTicket/my:BudgetMaster/my:BudgetLine[last()]", NamespaceManager);

    XPathNavigator NewRow = group.Clone();

    //Set each field value

    NewRow.SelectSingleNode("my:LineStatus", NamespaceManager).SetValue("test");

    NewRow.InsertAfter(group);

     Thanks,

     Jeff

  • 11-11-2008 07:39 AM In reply to

    Re: repeating table add rows programaticly

    Do you have a default value set on the field 'my:LineStatus'? Or a rule hanging about somewhere that might be doing that? Becuase in the code, you are creating a new group called NewRow and setting the value only on that field in that group.....

    By the way, the XPath you were using at first was taking the first Budget Line group and cloning it -- now you are cloning the last one. I suggested using 'last' if you changed to using Jimmy's method of using:

    CurrentView.ExecuteAction(ActionType.XCollectionInsert, "XmlToEdit");

    Either is fine -- just wanted you to be aware of what the difference was.

    Hilary Stoupa

  • 11-11-2008 08:44 AM In reply to

    Re: repeating table add rows programaticly

    I finally figured this out.  The issue is setting the values before inserting the new row.  It seems like when you do that, InfoPath keeps a pointer to the other row.  So once I inserted first and then set values, it works fine:

    XPathNavigator group = MainDataSource.CreateNavigator().SelectSingleNode("/my:ProjectTicket/my:BudgetMaster/my:BudgetLine[last()]", NamespaceManager);XPathNavigator NewRow = group.Clone();

    NewRow.InsertBefore(group);

    //Set each field value

    NewRow.SelectSingleNode("my:LineStatus", NamespaceManager).SetValue("test");

    NewRow.SelectSingleNode("my:Dept", NamespaceManager).SetValue("IT");

    NewRow.SelectSingleNode("my:CostQuantity", NamespaceManager).SetValue("2");

     

    Thank you for all the help!

    Jeff

  • 02-13-2009 07:10 AM In reply to

    Re: repeating table add rows programaticly

    Hi Hilary, hoping you can shine some light on this problem for me as I've spent hours searching the forums and am still not having any luck with this!  I have a relatively simple form for tracking overtime worked/paid - the user fills in the info (date, start time, end time) into a repeating table which then calculates "hours worked" and the "hours earned".  What I'd like is for the user to then click a button if they want the overtime to be paid, and have the "date" and "hours earned" automatically populate into a second repeating table.  This would need to be repeated for each instance of overtime, and a new row inserted into the secondary repeating table each time.

    Right now my data source looks like this:

    I've tried using the below code which I've kind of made up from what I could find on here but I can't even get the form to open in preview with it so I've obviously done something wrong!  Any help is greatly appreciated.

     Ben

    function CTRL89_7::OnClick(eventObj)

     {

    XPathNavigator group = MainDataSource.CreateNavigator().SelectSingleNode

    ("/my:OvertimeTracking/my:Payments/my:PaymentDetails[last()]", NamespaceManager);

    XPathNavigator NewRow = group.Clone(); NewRow.InsertAfter(group);

    //Set each field value NewRow.SelectSingleNode

    ("my:DateWorked", NamespaceManager).SetValue("my:Date"); NewRow.SelectSingleNode("my:HoursToBePaid", NamespaceManager).SetValue("my:HoursEarned"); }

  • 02-13-2009 12:07 PM In reply to

    Re: repeating table add rows programaticly

    Hello Ben,

     Here is a sample that we modifed that Hilary posted on another post.  We needed to add a row to the table we are in when the user clicks a button on the row.  This method copies the row clicked and adds it back into the table.  We use the sample xml file as a sort of template for adding rows.  I think you should be able to modify to suit your needs.  This sample works well for adding a new row to the table.  The issue with using the clone method is you still point to the old row you cloned.  ProjectTask is a line in the group ProjectTaskList.

    //Create a copy of current row and insert after current row

    XmlDocument sampleData = new XmlDocument();

    sampleData.Load(this.Template.OpenFileFromPackage("sampledata.xml"));

    XPathNavigator newProjectTask = sampleData.CreateNavigator().SelectSingleNode("/my:ProjectTicket/my:ProjectTaskList/my:ProjectTask", NamespaceManager).Clone();

    string OldGuid = e.Source.SelectSingleNode("my:ProjectTaskId", NamespaceManager).Value;

    newProjectTask.SelectSingleNode("my:DepartmentAbbrev", NamespaceManager).SetValue(e.Source.SelectSingleNode("my:DepartmentAbbrev", NamespaceManager).Value);

    newProjectTask.SelectSingleNode("my:Department", NamespaceManager).SetValue(e.Source.SelectSingleNode("my:Department", NamespaceManager).Value);

    newProjectTask.SelectSingleNode("my:ParentTaskId", NamespaceManager).SetValue(OldGuid);

    newProjectTask.SelectSingleNode("my:IncludedInChangeRequest", NamespaceManager).SetValue("True");

    newProjectTask.SelectSingleNode("my:ProjectTaskId", NamespaceManager).SetValue(Guid.NewGuid().ToString());

    newProjectTask.SelectSingleNode("my:ChangeOrderLineNumber", NamespaceManager).SetValue(GetField("/my:ProjectTicket/my:ChangeOrderNumber"));

    string TaskName = e.Source.SelectSingleNode("my:TaskName", NamespaceManager).Value + "-" + GetField("/my:ProjectTicket/my:ChangeOrderNumber");

    newProjectTask.SelectSingleNode("my:TaskName", NamespaceManager).SetValue(TaskName);

    e.Source.InsertAfter(newProjectTask);

  • 02-14-2009 08:15 AM In reply to

    Re: repeating table add rows programaticly

    Hiya Ben,

     I've always held that ExecuteAction is a better way to insert new items into repeating groups, as it does not require cloning a node (a node can't be cloned if there isn't one there to begin with), and takes the guesswork out of putting the node together manually.

    The main problem with your code is that you seem to be using C# 2007 code but it looks like your form is set up to use JScript.

    Your screenshot is not showing up as its address seems to be located on your intranet and is not accessible to us:

    http://blemain-intranet/sites/Intranet/accountsforms/test1/Picture10.png

    If you put the picture up on the internet where we all can see it, I can show you some code that would probably do what you want.

    Jimmy

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 04-09-2010 10:05 AM In reply to

    Re: repeating table add rows programaticly

    What do You do if you want the table to start with no items and add few at once?

    Ofer
  • 11-09-2011 06:52 AM In reply to

    Re: repeating table add rows programaticly

    Hi Hilary

    I was trying to get this to work, and after making a smaller change, I got it to work. As I always need to add 1 row to the table when the button is pressed, I have made the text box read only and set the value to 2.

    My code looks like this:

    Public Sub CTRL6_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    Dim xpath As String = "/my:myFields/my:field1"

    Dim field As XPathNavigator = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager)

    xpath = "/my:myFields/my:group1/my:group2"

    Dim group As XPathNavigator = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager)Dim rows As Integer = field.ValueAsInt

     

    Dim i As Integer

    For i = 1 To rows - 1Dim newRow As XPathNavigator = group.Clone()

    newRow.InsertAfter(group)

    Next i

     

    End Sub

    I would like to use this in a form we use for reviews. In each row in the table I have a text box which just shows which review we are at and a drop-down box which shows the result of the review, basically OK/ Not OK. I have been trying to add a condition to the code to ensure that a new row is only inserted when the result of the review is "Not OK". Unfortunately my programming skills are very rusty and I can't get it to work.

    Do you have any ideas to how this should be added to the code?

  • 07-19-2016 05:32 AM In reply to

    Re: repeating table add rows programaticly

     How would I programmatically add rows to a nested repeating tabled based on a drop down selection?

    I have a repeating section with a drop down, button, a repeating table and a hidden field that calculates how many rows to add to the table based on an external data source. I used the below code to add the correct amount of rows but when I add a new section and try to add rows it adds the same amount as it did in the first section.

                Dim xpath As String = "/my:myFields/my:AdminTool/my:AToolCount"
                Dim field As XPathNavigator = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager)
                Dim rows As Integer = field.ValueAsInt
                Dim i As Integer
                For i = 1 To rows - 1
                    CurrentView.ExecuteAction(ActionType.XCollectionInsert, "Tool_31")
                Next i

    Any help would be much appreciated. 

Page 3 of 3 (40 items) < Previous 1 2 3
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.