Email values from repeating table items - InfoPath Dev
in

InfoPath Dev

Email values from repeating table items

Last post 08-26-2009 12:04 PM by Hilary Stoupa. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 04-18-2009 11:19 AM

    Email values from repeating table items

    Hello,

    I've gotten good advice from here in the past so hopefully someone can help me with this one.  I'm sure it's not that hard, I'm just missing something as I am new to InfoPath.

    I have a form with several repeating sections.  I have a button at the end of each section to email the data.  I have used managed code to pull the values from the fields in the repeating section and add them into an email to be sent out to the vendor selected for that table.  The problem I have run into is that once I choose to add a new item, fill in all of the fields for that section, and then email it, it emails the data in the first repeating table. 

     Here is a sample of some of the code that I have for pulling the values:

             {

                XPathNavigator root = MainDataSource.CreateNavigator();
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(root.NameTable);
                nsmgr.AddNamespace("ns", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-02-18T23:26:16");
               

                //Gather the field values for this item.
                string csprojtitle = root.SelectSingleNode("/ns:myFields/ns:topHeading/ns:TopHeadingTable/ns:projectTitle", nsmgr).Value;
                //string csprojid = root.SelectSingleNode("/ns:myFields/ns:topHeading/ns:TopHeadingTable/ns:projectID", nsmgr).Value;
                string csitem = root.SelectSingleNode("/ns:myFields/ns:CardSpecifications/ns:CSItemSection/ns:CSItemVersion", nsmgr).Value;
                string quant = root.SelectSingleNode("/ns:myFields/ns:CardSpecifications/ns:CSItemSection/ns:CSQuantity", nsmgr).Value;

                ....

      So my question would be, since the field would change for each new repeating group created, how do I grab that new field name?         

    Thanks in advance for your help,

      Brett 

     

     

  • 04-19-2009 06:10 PM In reply to

    Re: Email values from repeating table items

    This code runs when you click a button? And that button is located INSIDE the repeating section? If so, you can use e.Source to get a reference to the repeating group the button is located inside, then relative paths, so:

    string quant = e.Source.SelectSingleNode("ns:CSQuantity").Value;

    Hilary Stoupa

  • 04-19-2009 06:57 PM In reply to

    Re: Email values from repeating table items

    Hello Hilary,

            First off, thank you so much for helping.  You've answered a few of my questions now and I appreciate your patience in dealing with a newbie.

    Actually, I had done some digging and found the e.Source.SelectSingleNode piece and had added it into my code.  I believe that it needs the Namespace Manager in there as well though, doesn't it.? I tried it without the nsmgr and it threw an error, so I added the nsmgr back in but I still get an "Object reference not set to an object instance" at the "string csprojtitle" line, basically the first line with the e.Source in use, which is what I've received ever since adding the e.Source.  Do I need to do something with my Namespace Manager? Any suggestions?

     

    Thanks again for your help,

      Brett

     

    Sorry, let me add the new code:


            public void CTRL_CS_Clicked(object sender, ClickedEventArgs e)
            {

                XPathNavigator root = MainDataSource.CreateNavigator();
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(root.NameTable);
                nsmgr.AddNamespace("ns", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-02-18T23:26:16");
               

                //Gather the field values for this item.
                string csprojtitle = e.Source.SelectSingleNode("ns:projectTitle", nsmgr).Value;
                //string csprojid = e.Source.SelectSingleNode("ns:projectID", nsmgr).Value;
                string csitem = e.Source.SelectSingleNode("ns:CSItemVersion", nsmgr).Value;
                string quant = e.Source.SelectSingleNode("ns:CSQuantity", nsmgr).Value;

     

     

     

     

  • 04-20-2009 06:35 PM In reply to

    Re: Email values from repeating table items

    Hello Hilary,

          Thanks again for your response to my question last night.  I sent a reply with some code modifications last night and just wanted to see if you had any ideas on what I might be missing.  I'm sorry to bother you and I apologize if I am interrupting by sending this email, I just wanted to check on this code.

     

    Thanks again for your help,

            Brett

  • 04-22-2009 01:15 PM In reply to

    Re: Email values from repeating table items

    Sorry for the delay, it has been a crazy week. You can just use this.NamespaceManager and you'll get the right one.

    string csprojtitle = e.Source.SelectSingleNode("ns:projectTitle", this.NamespaceManager).Value;

     Put a breakpoint in your code at that line, and run the code in debug. Hover over e.Source to make sure you've got the repeating group that has the ns:projectTitle node. Is the button inside the repeating section bound to the repeating group that has a child of ns:projectTitle?

    Hilary Stoupa

  • 04-22-2009 09:27 PM In reply to

    Re: Email values from repeating table items

    Hello Hilary,

          Thanks again for your help.  I've added the code and still have some problems.  Does it need to be "this.NamespaceManager" or "this.nsmgr" as I defined.  I tried both and had errors both ways.  With the this.nsmgr it said that there was not a definition for nsmgr, and with this.NamespaceManager it tells me that the Namespace prefix 'ns' is not defined.

          Sorry, any other thoughts?  I appreciate your help.  I'm new to infopath and C# and so am kind of fumbling at this point.  Just let me know what you think.

     

    Thanks,

          Brett

  • 04-23-2009 08:08 AM In reply to

    Re: Email values from repeating table items

    I'm looking at the code snippet you posted in your first post -- that was working, just always bringing back the first items in each repeating group, is that correct? I also noticed that you are pulling fields from more than group.... can you post your form here? Under Options when you reply, attach the .xsn....

    Hilary Stoupa

  • 04-23-2009 08:56 AM In reply to

    Re: Email values from repeating table items

    Hello Hilary,

         Thanks for sticking with this.  Yes, the button was working, just only bringing in the first item.  The button is part of the repeating section as well.  I am pulling some fields from a different group that is up in the title area.  There are fields that will need to go out on every email, and then other fields that will only go out on the emails regarding that particular item.

         I've attached the form, I have to run into a meeting but will be available in about an hour.  I hate to ask, but is there any way I could call you or give you my number?  You've been so helpful and I don't want to waste any of your time, but I'm getting a bit desperate with this and would love to ask some questions.  Just let me know if that would be ok.

     Thanks again for your help,

         Brett 

  • 04-23-2009 09:30 AM In reply to

    Re: Email values from repeating table items

    Since your namespace manager code was working for you in your initial sample, stick with that.

    Looking at your schema and the placement of your button, I'd think you'd get values from these lines:
                string csitem = e.Source.SelectSingleNode("ns:CSItemVersion", nsmgr).Value;
                string quant = e.Source.SelectSingleNode("ns:CSQuantity", nsmgr).Value;

    But should go back to your original lines for these:
                string csprojtitle = root.SelectSingleNode("/ns:myFields/ns:topHeading/ns:TopHeadingTable/ns:projectTitle", nsmgr).Value;
                string csprojid = root.SelectSingleNode("/ns:myFields/ns:topHeading/ns:TopHeadingTable/ns:projectID", nsmgr).Value;

    Since those items aren't repeating.

    Using your template, this gets values for me:

    XPathNavigator root = MainDataSource.CreateNavigator();
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(root.NameTable);
    nsmgr.AddNamespace("ns", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-02-18T23:26:16");
     
    //Gather the field values for this item.
    string csprojtitle = root.SelectSingleNode("/ns:myFields/ns:topHeading/ns:TopHeadingTable/ns:projectTitle", nsmgr).Value;
    string csprojid = root.SelectSingleNode("/ns:myFields/ns:topHeading/ns:TopHeadingTable/ns:projectID", nsmgr).Value;
    string csitem = e.Source.SelectSingleNode("ns:CSItemVersion", nsmgr).Value;
    string quant = e.Source.SelectSingleNode("ns:CSQuantity", nsmgr).Value;
    Hilary Stoupa

  • 04-23-2009 12:22 PM In reply to

    Re: Email values from repeating table items

    Hey Hilary,

          Thank you thank you thank you...you really saved me on this.  It appears to be working.  I have a few more questions if you don't mind but I can open a new post for those if you'd like.  I need to do some more digging first anyway.  This was the major piece though.  Thank you so much for helping me out on this.  Whew...so glad to get this fixed, that was driving me nuts. 

    Brett

  • 04-23-2009 12:52 PM In reply to

    Re: Email values from repeating table items

    Glad to help. Do open new threads if your new topics are different than this thread.

    I think that understanding XPath and how to reference the different fields in your form is key to being able to get very far with InfoPath (and I still struggle sometimes myself!). When you have time, I really recommend this tutorial from W3 schools, it may help you along.

    Hilary Stoupa

  • 08-26-2009 05:49 AM In reply to

    Re: Email values from repeating table items

    Hello,

    I found this discussion quite useful for me. I am sure I am not the only one reading this discussion, so I would like to provide my findings.

    I had a few problems to make this work.

    Here are the problems:

    • In my case, the method selectSingleNode accepted only single argument - queryString. 
    • the queryString have to start with "@". //I am beginner in XPath so I tried almost every option - d:myField, /d:myField, /myField, myField... and finally @myField!
    • The method itself has to start with lower case. //no such method in case of SelectSingleNode
    Here is my working example:

    function btnViewDetails::OnClick(eventObj) {
      //I have repeating table with one row per application and I want to get the application number of selected row
      var myNode = eventObj.Source.selectSingleNode("@APP_NO");
      var myNodeText = "";
      if (myNode != null) {
        myNodeText = myNode.text;
      }
      //Now the myNodeText holds the value of the "application number" field of selected row
      XDocument.UI.Alert(eventObj.Source.xml);
    }

    Notes: tested on InfoPath 2003 SP3, coded in JScript

  • 08-26-2009 12:04 PM In reply to

    Re: Email values from repeating table items

    Hi--

    The sample code was C# for the 2007 object model -- which does use upper case for SelectSingleNode. This also explains why you only needed to pass in the XPath to the node, the method used to work differently.

    YOUR XPath was to an attribute. Someone else's may be to an element. The namespace could be different. In InfoPath 2007, we can right click on a node in our data source and use 'Copy XPath' to get the correct XPath to the field. Sadly, there is no equivalent in IP 2003. Sometimes it is helpful to save your form as source files and look at the sampledata.xml or the template.xml to figure out the correct XPath.

    Thanks for posting your IP 2003, JScript code!

    Hilary Stoupa

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