Modifying field in a repeating table - InfoPath Dev
in

InfoPath Dev

Modifying field in a repeating table

Last post 08-29-2011 10:46 AM by kmhaga03. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 08-26-2011 12:57 PM

    Modifying field in a repeating table

    Trying to remove some characters from some fields after they have been pulled in.

     This is what I have but it is only modifying the first field:

    public void Ready_20_for_20_CCB__ows_Requester_attr_Changed(object sender, XmlEventArgs e)
            {
                string substring;
                int start;
                DataSource ReadyForCCB = this.DataSources["Ready for CCB"];
                XPathNavigator domNav = ReadyForCCB.CreateNavigator();
                XPathNodeIterator rows = domNav.Select("/xml/rs:data/z:row", NamespaceManager);
               while (rows.MoveNext())
               {

                   XPathNavigator Requestor = rows.Current.SelectSingleNode("/xml/rs:data/z:row/@ows_Requester", NamespaceManager);
                   substring = Requestor.Value;
                   start = substring.IndexOf("#");
                   substring = substring.Substring(start+1);
                   Requestor.SetValue(substring);

                }

     

    Any help is appreciated.

  • 08-26-2011 02:01 PM In reply to

    Re: Modifying field in a repeating table

    You need relative XPath instead of absolute.

    Change this:

    XPathNavigator Requestor = rows.Current.SelectSingleNode("/xml/rs:data/z:row/@ows_Requester", NamespaceManager);

    To this:

    XPathNavigator Requestor = rows.Current.SelectSingleNode("@ows_Requester", NamespaceManager);

    rows.Current is going to be a z:row node - you want to select the @ows_Requester attribute that belongs to this row. Your full XPath in your code was always going to select the first field.

    Hilary Stoupa

  • 08-29-2011 10:46 AM In reply to

    Re: Modifying field in a repeating table

    Thanks! That works!

    Now, on load, my form strips the ugly characters.

    Here is the completion of it, in case anyone else is having a similar problem:

    public void FormEvents_Loading(object sender, LoadingEventArgs e)
            {
                //repeating field requestor
                XPathNavigator Requestor;

                //repeating field functional
                XPathNavigator Functional;

                //repeating field programdirector
                XPathNavigator programDirector;

                //declare datasource (this is an xml datasource to a specific sharepoint list)           
                DataSource ReadyForCCB = this.DataSources["Ready for CCB"];
               
                XPathNavigator domNav = ReadyForCCB.CreateNavigator();
                XPathNodeIterator rows = domNav.Select("/xml/rs:data/z:row", NamespaceManager);

                //iterate through the rows of the datasource
                while (rows.MoveNext())
                {
                    //store the value of requestor in the current row
                    Requestor = rows.Current.SelectSingleNode("@ows_Requester", NamespaceManager);

                    //store the value of functional in the current row
                    Functional = rows.Current.SelectSingleNode("@ows_IMO_x002f_PM_x0020_Name", NamespaceManager);

                    //store the value of programdirector in the current row
                    programDirector = rows.Current.SelectSingleNode("@ows_Program_x0020_Director", NamespaceManager);

                    //set the value of the fields with the chars stripped
                    Requestor.SetValue(RemoveChars(Requestor));
                    Functional.SetValue(RemoveChars(Functional));
                    programDirector.SetValue(RemoveChars(programDirector));
                }
            }
            public string RemoveChars(XPathNavigator x)
            {//function to strip the characters.

                //set the value of substring equal to that of the XPathNavigator being passed in, i.e., Requestor, Functional, programDirector
                string substring = x.Value;

                //strip the chars before and including the #
                substring = substring.Substring(substring.IndexOf("#") + 1);

                //return the stripped value
                return substring;

            }

     

    Thanks again for your help, Hilary.

     

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