Accessing the fields of a repeating table through code - InfoPath Dev
in

InfoPath Dev

Accessing the fields of a repeating table through code

Last post 12-11-2007 05:10 AM by zeroecho. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 11-28-2007 05:41 AM

    • itzzme
    • Not Ranked
    • Joined on 11-23-2007
    • Posts 8

    Accessing the fields of a repeating table through code

    I have a repeating table which is bound to a SharePoint list.

    I need to access the loop through the records in the table through a code.(This action is required to be performed in a button_Click handler)

    The XPath of the repeating table field is  ("/dfs:myFields/dfsataFields/dfs:Risk_Actions/@Situation.

    The code i'm trying to use is

    XPathNodeIterator actSituation = MainDataSource.CreateNavigator().Select("/dfs:myFields/dfsataFields/dfs:Risk_Actions/@Situation", NamespaceManager);

    while (actSituation.MoveNext())

    {

    }

    The control does not get into the while loop.

    Kindly help!!

     Thanks

  • 11-28-2007 08:11 PM In reply to

    • itzzme
    • Not Ranked
    • Joined on 11-23-2007
    • Posts 8

    Re: Accessing the fields of a repeating table through code

    sorry..I mis -typed the XPath in the post.

    The Xpath is "/dfs:myFields/dfs:dataFields/dfs:Risk_Actions/@Situation"

     

    Kindly help

  • 11-30-2007 02:57 PM In reply to

    Re: Accessing the fields of a repeating table through code

    I'd guess the problem is that your xpath selects the attribute field. If dfs:Risk_Actions is your repeating field, don't include "/@Situation" in your xpath; otherwise, the returned node set will contain the Situation attribute of the first node. 

  • 12-11-2007 05:10 AM In reply to

    • zeroecho
    • Top 500 Contributor
      Male
    • Joined on 10-23-2007
    • Yorkshire, UK
    • Posts 39

    Re: Accessing the fields of a repeating table through code

    I've got a similar problem in that I've got a repeating table and whilst I can go through the while loop for each of the Rows in the table, the values don't change.

    i.e. I'm trying to pull a list of activities and break them down into individual items to post to a sharepoint list for each day spent on that activity. e.g. InfoPath development is done Mon-Sunday for 2hours each day, and then SharePoint development is done Mon-Sun 4hours a day, there should be 14 items in the sharepoint list, 7 for infopah dev listing the breakdown for each day and 7 for sharepoint dev for each day. What I actually get is 14 items, but those 14 would be the infopath dev row repeated twice and no sharepoint dev at all. Here's my code

    Thanks for any help I can get with this. I feel so close to getting it sorted, just stuck on this tiny bit!

    First I look at the MainDataSource and then create an XPathNodeIterator which points to my repeating table

    XPathNavigator domNav = MainDataSource.CreateNavigator();

    XPathNodeIterator activity = domNav.Select("/my:TimesheetDetails/my:EmployeeInformation/my:TimeReporting/my:PerActivity", NamespaceManager);

     

    My current method of collecting the node information is using this style of line

    string taskActivity = activity.Current.SelectSingleNode(perActivity + "/my:TaskActivity", NamespaceManager).Value; (where perActivity = the path to my repeating table)

    The problem with this method is that it only selects the first node. If I call activity.Current.Value; the value is incrementing using the while(activity.MoveNext()) command, but actually selecting the children of my repeating node doesn't work.

    If I try to change the xpath in selectsinglenode to something like

    string location = activity.Current.SelectSingleNode("/my:Location", NamespaceManager);

    or

    string location = activity.Current.SelectSingleNode("/@my:Location", NamespaceManager);

    I get a "System.NullReferenceException: Object reference not set to an instance of an object." so it doesn't like that xpath.

     

    The actual full xpath for the fields I am trying to query is "/my:TimesheetDetails/my:EmployeeInformation/my:TimeReporting/my:PerActivity/my:Location" where PerActivity is the repeating table in my form I am trying to iterate through.

    I am thinking that maybe activity.Current.SelectChildren or .SelectDescendants is the correct way of what I'm trying to do but that just pulls another NodeIterator out rather than the data I need.

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