Traversing through rows in repeating table - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Traversing through rows in repeating table

Last post 07-10-2009 02:40 AM by GazM. 13 replies.
Page 1 of 1 (14 items)
Sort Posts: Previous Next
  • 12-28-2008 03:56 AM

    Traversing through rows in repeating table

    Hi,
    I am using Infopath 2003 SP2 and prg language is VBScript.
    I have an access table q_inflow_entry and the data source looks like this: /dfs:myFields/dfs:dataFields/d:q_inflow_entry/
    My repeating table control retrieves list of records which have been assigned to a user but not yet processed. I need to let the user add records to the same control.
    I am using XDocument.View.ExecuteAction "xCollection::insert", "q_inflow_entry_1" to add a new row to a repeating table. How can I set values of fields like inflow_entered_by, inflow_entered_date programmatically as soon as the user inserts a new row? I tried using the following:

    XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:q_inflow_entry/@ inflow_entered_by ").text()="UOM002"
    But the above statement updates value of field inflow_entered_by in the first row in the repeating table. Can someone please help? I also need code to let the user delete a row because there are a few checks to be performed before a delete. My main problem is that I am not able to figure out how to find the row in which user is making a change. Need more info on XDocument.
     
    Thanks a mil in advance!!!

  • 12-28-2008 10:17 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Traversing through rows in repeating table

  • 01-01-2009 02:43 AM In reply to

    Re: Traversing through rows in repeating table

    Hi Shiva. Thanks for your help and sorry I was so late to reply on this one. I went through the links you specified and some other links. I am using VBScript.

    My code looks like:

    Sub msoxd__q_inflow_entry_inflow_assigned_to_attr_OnAfterChange(eventObj)

      if (eventObj.OldValue <> "") then

         dim userRowNode  

         userRowNode = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:q_inflow_entry")

         userRowNode.selectSingleNode("reassigned").text() = "Y"

      end if

    End Sub

    But I get a runtime  error 'Object doesn't support this property or method'.  I tried

    dim userRowNode as XMLDOMNode

    This is also not supported. Can you help? Most of the code on this site that I would like to use is in Jscript. Did not see as many examples in VBScript.

    I have tried to use XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:q_inflow_entry[position() = 15]/@reassigned").text() = "Y"

    But I need to know the position of the current row. I cannot hard code. 

     

  • 01-01-2009 08:56 PM In reply to

    Re: Traversing through rows in repeating table

    Hi, I think I have searched this forum for days to get an answer to my problem. I went through most of the posts in which looping through a repeating table was discussed, checked position() function. I have checked the link http://www.infopathdev.com/forums/p/5091/19631.aspx#19631 and tried to use node.selectSingleNode in VBScript but it doesn't work. I am sure it must be very simple and I am missing out on something. I am going nuts trying to find a way out. Someone please help. Many thanks & regards.

  • 01-01-2009 10:26 PM In reply to

    Re: Traversing through rows in repeating table

    When you insert a new row into the table, the row is added to the end of the table, right?

     If so, you should be able to use

    XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:q_inflow_entry[last()]")

    to access the last row.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-02-2009 05:34 AM In reply to

    Re: Traversing through rows in repeating table

    With regard to your second question (deleting rows), you can place a button in the repeating table that will handle deletion.  The button's event handler will look something like this:

    Sub CTRL5_5_OnClick(eventObj)
       ' Write your code here
    End Sub

    eventObj.Source is a reference to the node in the repeating group corresponding to the row of the table where the button was clicked. So in your example:

    eventObj.Source.selectSingleNode("@inflow_entered_by")

    would select the inflow_entered_by attribute in the row where the button was clicked.

    Once you have set whatever values you need and made whatever checks you need to perform, you can use this to remove the row where the button was clicked:

    XDocument.View.ExecuteAction "xCollection::remove", "q_inflow_entry_1"

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-02-2009 06:07 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Traversing through rows in repeating table

    Hello,

    In your code check once the XPath of your field. XPath should be correct otherwise it won't work.

    node.selectSingleNode("XPath of your field")

    If you are using InfoPath 2007 then,

    node.selectSingleNode("XPath of your field", this.NamespaceManager)

  • 01-02-2009 06:19 AM In reply to

    Re: Traversing through rows in repeating table

    Hi Jimmy. Thanks for your help. Let me explain what i am trying to do in detail. We have telexes coming in from all over the world in another system. The telexes have to be taken care of within the stipulated turn time. We call it inflow. Someone needs to keep track of all the inflow. That user should be able to add new inflow to the table, assign inflow to user while adding, reassign pending inflow to some other user, all in one screen. I retrieve all the rows (or inflow/telex records) which are still pending. I need to capture the date/time when the inflow was added to the system, date/time when inflow was assigned and whether it was reassigned.

    My repeating table on the form looks like below with multiple rows retrieved from database.

    Sr.No.
    Week
    Inflow Date
    Request Id
    Deal Source
    Inflow Assigned Date
    Assigned To
    Out Of Queue

    User not only adds to the repeating table but also makes updates. I need to capture the current row no so that I can put my code in the OnAfterChange event of inflow_assigned_to field to check whether update was done in that row. How can I achieve such functionality using VBScript? Unfortunately we are using IP2003 and not IP2007.

    May be I had not described my problem with enough details in the previous posts. I'd be absolutely relieved if someone suggests a solution. Thanks in advance.

  • 01-02-2009 07:50 AM In reply to

    Re: Traversing through rows in repeating table

    You can track changes to the assignedTo field by placing an OnAfterChange event handler on that node, but there is a bit of a catch because from the event handler's perspective a row insertion looks exactly like a user's value modification so we have to be a little tricky.  I suggest the following.

    Add a new node my:ignoreInserts to your main data source, and make it a boolean value.  Whenever you query your secondary data source from a rule, set this node's value to true right before the query, and to false right after.  Your form's event handlers can check this value to know whether a change to a node was due to a query/row insertion, or due to a user modification.

     Also add these two subroutines and one function to your VBScript code:

    Sub IgnoreInserts
         XDocument.DOM.selectSingleNode("/my:myFields/my:ignoreInserts").text() = "true"
    End Sub
    Sub DoneIgnoringInserts 
         XDocument.DOM.selectSingleNode("/my:myFields/my:ignoreInserts").text() = "false"
    End Sub
    Function IgnoreInsertsValue() 
         IgnoreInsertsValue = XDocument.DOM.selectSingleNode("/my:myFields/my:ignoreInserts").NodeTypedValue
    End Function

    Call the first subroutine before adding a row to the table to set my:ignoreInserts to true, and call the second one after adding the row to set it back to false, so inserting a row would look something like this

    IgnoreInserts   'Set my:ignoreInserts to true
    XDocument.View.ExecuteAction "xCollection::insert", "group2_1"
    'Make any changes you need to make to the new row
    DoneIgnoringInserts  'Restore my:ignoreInserts to false

    Then all you've got left to do is write the OnAfterChange event handler.  In the event handler, you will need some conditional code to check the value of my:ignoreInserts

    If IgnoreInsertsValue() = "false" and eventObj.Operation = "Insert" Then
    ' insert the code you want to perform here
    'eventObj.OldValue holds the previous value of the field
    'eventObj.NewValue holds the new value of the field
    'you can access the element to which this attribute belongs using eventObj.Site.selectSingleNode("..")
    End if

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-05-2009 08:53 AM In reply to

    Re: Traversing through rows in repeating table

    Hi Jimmy. Thanks for your suggestions. Got to learn a few things. Today, I tried what you suggested. My code in the OnAfterChange event of inflow_assigned_to field now looks like below:

    Sub msoxd__q_inflow_entry_inflow_assigned_to_attr_OnAfterChange(eventObj)
     
        If eventObj.IsUndoRedo Then
         ' An undo or redo operation has occurred and the DOM is read-only.
         Exit Sub
        End If

        'Row modified
        If IgnoreInsertsValue() = "false" and eventObj.Operation = "Insert" Then
     
         'assigning for the first time
         if (eventObj.OldValue = "") and (eventObj.NewValue <> "") then
             eventObj.Site.selectSingleNode("inflow_assigned_date") = now()
             eventObj.Site.selectSingleNode("inflow_assigned_by") = m_user_id
             msgbox("assigning for the first time")
         end if
      
         'reassigning
         if (eventObj.OldValue <> "") then    'set reassigned flag
             eventObj.Site.selectSingleNode("reassigned") = "Y"
             msgbox("reassigning")
         End if
     
        End if

    End Sub

    Unfortunately, three lines stated below throw error as "Object doesn't support this property or method."

    eventObj.Site.selectSingleNode("inflow_assigned_date") = now()
    eventObj.Site.selectSingleNode("inflow_assigned_by") = m_user_id
    eventObj.Site.selectSingleNode("reassigned") = "Y"

    Is it because the Site property is read only? Then how do I set values for other fields in the same line?

  • 01-05-2009 09:16 AM In reply to

    Re: Traversing through rows in repeating table

    I think you need to be assigning to the text() property of the nodes, as in:

    eventObj.Site.selectSingleNode("inflow_assigned_date").text() = now()
    eventObj.Site.selectSingleNode("inflow_assigned_by").text() = m_user_id
    eventObj.Site.selectSingleNode("reassigned").text() = "Y"

    Also, are those nodes children of inflow_assigned_to?  If not, I would think you would need to move up one node in the DOM tree to get to them:

    eventObj.Site.selectSingleNode("../inflow_assigned_date").text() = now()

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-08-2009 08:24 PM In reply to

    Re: Traversing through rows in repeating table

    Hey Jimmy, you are correct. The columns inflow_assigned_to, inflow_assigned_date, inflow_assigned_by and reassigned are siblings. I did as you suggested. And now the code actually works!!! Here is how it looks after the changes:

    If IgnoreInsertsValue() = "false" and eventObj.Operation = "Insert" Then
     
         'assigning for the first time
         if (eventObj.OldValue = "") and (eventObj.NewValue <> "") then
             eventObj.Site.selectSingleNode("../@inflow_assigned_date") = now2_ISO_Date(now())
             eventObj.Site.selectSingleNode("../@inflow_assigned_by") = m_user_id
         end if
      
         'reassigning
         if (eventObj.OldValue <> "") then    'set reassigned flag
             eventObj.Site.selectSingleNode("../@reassigned") = "Y"
         End if
     
    End if

    It took me some time to really understand the xDocument, DOM, eventObj etc. Thanks a LOT for all your help, especially when not much help is available for the combination (IP2003 and VBScript) I am using.

  • 07-09-2009 06:06 AM In reply to

    • GazM
    • Top 200 Contributor
      Male
    • Joined on 11-09-2005
    • England
    • Posts 54

    Re: Traversing through rows in repeating table

    Jimmy

    I have tried the last() method (as mentioned earlier in this thread) to pick up the last row in my repeating table but it doesn't seem to work. It is picking up the first row of the table every time.

    Dim oComment

    'creates value for Comment

    Set oComment = XDocument.DOM.selectSingleNode("//my:myFields/my:Approval/my:Response/my:Comment[last()]")

    The code is used to extract the text from my:Comment and insert it into an automated email response triggered from a button control. I am using IP2003 SP1

    Gary

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

    • GazM
    • Top 200 Contributor
      Male
    • Joined on 11-09-2005
    • England
    • Posts 54

    Re: Traversing through rows in repeating table

    Doh!

    Fixed this one myself. Previous code was trying to pick the field rather than the row.

    This works:

    Dim oComment

    Dim oLastRow

    Set oLastRow = XDocument.DOM.selectSingleNode("//my:myFields/my:Approval/my:Response[last()]")

    Set oComment = oLastRow.selectSingleNode("my:Comment")

    Gary

Page 1 of 1 (14 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.