Retrieving Field Value From Repeating Section - InfoPath Dev
in

InfoPath Dev

Retrieving Field Value From Repeating Section

Last post 06-24-2011 02:06 PM by Hilary Stoupa. 15 replies.
Page 1 of 2 (16 items) 1 2 Next >
Sort Posts: Previous Next
  • 06-23-2011 10:36 PM

    Retrieving Field Value From Repeating Section

    Hi All,

    I am a novice in Infopath development - I am facing something that I thought would be very easy to implement but has caused me a loss of one whole day figuring out

    SCENARIO

     I have an IP form with repeating sections. Each repeating section has 6 sections. I have implemented a button in each section that essentially transfers/copies the xml of one section to all other remaining sections in the repeating section.

    PROBLEM

    The xml is transferred successfully for the first repeating section - however when I enter another repeating section and copy the xml, it remembers the contents of the first repeating section. I cannot copy contents of sections in the second repeating sections, it always remembers the context of the first repeating sections. Is there an API that I can take use and get select the context of the repeating section?

    DATA STRUCTURE

    • Specializations (Repeating Section Starts here)
    • SemesterDetailInformation
    • Year1
    • Year2

    CODE
        public void CopyYear2_Clicked(object sender, ClickedEventArgs e)
        {
          // Write your code here.
          XPathNavigator nav = MainDataSource.CreateNavigator();
          //Dropdown selected value
          XPathNavigator yearDDL = nav.SelectSingleNode("/my:Proposal/my:Specializations/my:Specialization/my:SemesterDetailInformation/my:Year2/my:YearSelection", NamespaceManager);
          XPathNavigator year2 = nav.SelectSingleNode("/my:Proposal/my:Specializations/my:Specialization/my:SemesterDetailInformation/my:Year2", NamespaceManager);
          CopyYear(yearDDL.Value, year2, 2);
        }
    


     

        public void CopyYear(string Year,XPathNavigator copyFromYear,int yearNumber)
        {
          XPathNavigator nav = MainDataSource.CreateNavigator();
          XPathNavigator yearDDL = nav.SelectSingleNode("/my:Proposal/my:Specializations/my:Specialization/my:SemesterDetailInformation/my:Year1/my:YearSelection", NamespaceManager);
          XPathNavigator pgmLength = nav.SelectSingleNode("/my:Proposal/my:ProgramLenght", NamespaceManager);
          int length = Convert.ToInt32(pgmLength.Value);
          //Copy Year From
          XPathNavigator copyToYear;
          if (Year == "Year 1")
          {
            copyToYear = nav.SelectSingleNode("/my:Proposal/my:Specializations/my:Specialization/my:SemesterDetailInformation/my:Year1", NamespaceManager);
            DeleteNil(copyToYear);
            copyToYear.InnerXml = copyFromYear.InnerXml;
          }
          if (Year == "Year 2")
          {
            copyToYear = nav.SelectSingleNode("/my:Proposal/my:Specializations/my:Specialization/my:SemesterDetailInformation/my:Year2", NamespaceManager);
            DeleteNil(copyToYear);
            copyToYear.InnerXml = copyFromYear.InnerXml;
          }
    }
    

    Please advise how I get the context of the repeating section.

    Thanks

  • 06-24-2011 01:05 AM In reply to

    Re: Retrieving Field Value From Repeating Section

    Hi aszia787,

    We do this all the time with qRules and the xpath functions for preceding-sibling or current. Lots of posts on this type of thing. Your code could have a bug, but the biggest issue with coding this is that it hardcodes a dependency to your data source. So, if your data source changes, you have to recompile. qRules doesn't do this. I encourage you to download a free trial copy and use the copy commands to do this. Make sure you copy using a relative xpath and the preceding-sibling or current command - search for those. No code needed.

     

    Patrick Halstead
    Project Manager at Qdabra
  • 06-24-2011 08:10 AM In reply to

    Re: Retrieving Field Value From Repeating Section

    Hi Patrick, Thank you very much for your reply. I am not sure if I can use any third party tool for my development. I would prefer going with the the XPath functions. Is there any blog or code in XPath function that you may redirect to. Thanks again.
  • 06-24-2011 08:27 AM In reply to

    Re: Retrieving Field Value From Repeating Section

    You are using absolute XPath to get your node - that will always return the first node. Look into the ClickedEventArgs.Source property and use relative XPaths.

    Hilary Stoupa

  • 06-24-2011 09:03 AM In reply to

    Re: Retrieving Field Value From Repeating Section

    Hilary, Your post makes sense - I debugged using e.Source.OuterXml.ToString() and found myself on the current node, however I am not sure what would be the syntax of getting relative path of the node whose value I want to retrieve. For e.g I have a field "YearSelection" - how would I retrieve the value using e.Source as relative path. You may see my earlier post that has the schema of the repeating section for reference. Thanks a lot.
  • 06-24-2011 09:17 AM In reply to

    Re: Retrieving Field Value From Repeating Section

    You said your button was in a section - the section is bound to your repeating group, Specialization, right? So you could get a node like this:

     XPathNavigator yearDDL = e.Source.SelectSingleNode("my:SemesterDetailInformation/my:Year2/my:YearSelection", NamespaceManager);

    Hilary Stoupa

  • 06-24-2011 10:01 AM In reply to

    Re: Retrieving Field Value From Repeating Section

    Hilary,

     Thank you very much for your patience - You got the architecture of the sections and repeating sections correct however when I run the code you mentioned it returns me a NULL value.

     I will further clarify the data structure for you:

    • Specializations (Group)
      • Specialization (Repeating Section)
        • SemesterDetailInformation (Group)
          • Year 1 (Group)
            • YearSelection (Dropdown field in Group Year 1)
          • Year 2 (Group)
    public void CopyYear2_Clicked(object sender, ClickedEventArgs e)

    {

    // Write your code here.

    XPathNavigator nav = MainDataSource.CreateNavigator();

    //Dropdown selected value

    XPathNavigator yearDDL = nav.SelectSingleNode("/my:Proposal/my:Specializations/my:Specialization/my:SemesterDetailInformation/my:Year2/my:YearSelection", NamespaceManager);XPathNavigator year2 = nav.SelectSingleNode("/my:Proposal/my:Specializations/my:Specialization/my:SemesterDetailInformation/my:Year2", NamespaceManager);

    CopyYear(yearDDL.Value, year2, 2);

    }

     Writing e.Source.SelectSingleNode("my:SemesterDetailInformation/my:Year2/my:YearSelection", NamespaceManager"); returned a null value

    Thanks again for your help and patience.

  • 06-24-2011 10:28 AM In reply to

    Re: Retrieving Field Value From Repeating Section

    Where is your button? Is it in Specialization?

    Run in debug, and take a look at e.Source to see what node it is.

    Hilary Stoupa

  • 06-24-2011 10:53 AM In reply to

    Re: Retrieving Field Value From Repeating Section

    I was able to get the value of the field from the repeating section - I had to write e.Source.SelectSingleNode("YearSelection").

    I can copy the current value in the selected dropdown field "YearSelection" - my requirement is to copy the xml of the section from where the button was pressed (Year 1). I dont think I can do the same with year, each time when I try selecting the SingleNode of the year by e.SelectSingleNode("Year1"), it gives me an exception "Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function."

    Is there a workaround to get the node of the current group? Thanks.

  • 06-24-2011 11:05 AM In reply to

    Re: Retrieving Field Value From Repeating Section

    e.Source.SelectSingleNode("YearSelection", NamespaceManager)

    Hilary Stoupa

  • 06-24-2011 11:14 AM In reply to

    Re: Retrieving Field Value From Repeating Section

    This gets me the current value of the drop down list, not the content of the group Year1 under which YearSelection lies in.
  • 06-24-2011 12:10 PM In reply to

    Re: Retrieving Field Value From Repeating Section

    This is why I keep asking where your button is located.

    At any rate, it sounds as if you are saying that the button is in Year 1? Is that the case? If so, just e.Source would get you the Year 1 node. Again, you should run debug, see what the value of e.Source is.

    Hilary Stoupa

  • 06-24-2011 12:27 PM In reply to

    Re: Retrieving Field Value From Repeating Section

    Yes Hilary - I am sorry I should have mentioned the place of the button and e.Source is where Year 1 lies.I need to copy the content of Year 1 section (e.Source) to another section Year 2 (the value of dropdown list item), is it possible copying the content to another section in the same repeating section?  BTW Year 2 section is a replica of Year 1.

     Thanks again - I know I have been a pain in the butt but I have progressed to the point where I see some light :)

  • 06-24-2011 01:02 PM In reply to

    Re: Retrieving Field Value From Repeating Section

    You aren't a pain, I'm just cranky today. :-}

    You need to get Year 2 again using a relative path...

    So:

    e.Source.SelectSingleNode("../my:Year2", NamespaceManager)

    The ".." takes you from Year1 back up to SemesterDetailInformation, and from there you can select Year2.

    Hilary Stoupa

  • 06-24-2011 02:00 PM In reply to

    Re: Retrieving Field Value From Repeating Section

    Hilary - You are a Messaih!

    You are as gorgeous as your picture is. I have never found anyone so patient and yet at the same time cool to answer stupid questions from the likes of dolts like myself.

     I have started learning Infopath - rather was forced to learn as was thrown in IP project. I missed ASP.Net and SP object model and thought this may not be achievable in Infopath. Kudos to your patience and thanks a ton.

     

     

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