Custom coded C# email button issue - InfoPath Dev Sign in | Join | Help in Newbie Questions InfoPath (Entire Site) InfoPath Dev InfoPath Dev is dedicated to bringing you the information and tools you need to be successful in your Microsoft Office InfoPath development projects. Home Blogs Forums Photos Downloads InfoPath Dev » InfoPath » Newbie Questions » Custom coded C# email button issue Custom coded C# email button issue Last post 11-12-2009 09:43 AM by [email protected]. 7 replies. Page 1 of 1 (8 items) Sort Posts: Oldest to newest Newest to oldest Previous Next 11-11-2009 12:47 PM [email protected] Joined on 11-04-2009 Posts 12 Custom coded C# email button issue Reply Contact Hello All! Wondering if anyone would be able to help me. I've a simple form with a repeating table inside, there are only 4 columns. The last column is a checkbox where if the box is checked, it'll send an email of the data on that row to someone when the button is clicked. What it's happening right now is that, it only send the 1st row of data when I've about 4 out of 10 rows checked. Any idea what I'm doing wrong? Thank you very much in advance! 11-11-2009 01:59 PM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Custom coded C# email button issue Mark as Not AnswerMark as Answer... Reply Contact Hi: Does the button have code on it to do this? Can you post your code? Hilary Stoupa 11-11-2009 03:13 PM In reply to [email protected] Joined on 11-04-2009 Posts 12 Re: Custom coded C# email button issue Mark as Not AnswerMark as Answer... Reply Contact Hello Hilary! Thank you for your quick respond! Here is the code: using Microsoft.Office.InfoPath; using System; using System.Windows.Forms; using System.Xml; using System.Xml.XPath; using mshtml;namespace TestEmail { public partial class FormCode { // Member variables are not supported in browser-enabled forms. // Instead, write and read these values from the FormState // dictionary using code such as the following: // // private object _memberVariable // { // get // { // return FormState["_memberVariable"]; // } // set // { // FormState["_memberVariable"] = value; // } // } // NOTE: The following procedure is required by Microsoft Office InfoPath. // It can be modified using Microsoft Office InfoPath.public void InternalStartup() {((ButtonEvent)EventManager.ControlEvents["btnSend"]).Clicked += new ClickedEventHandler(btnSend_Clicked); }public void btnSend_Clicked(object sender, ClickedEventArgs e) { // Write your code here.string valueField1 = null; string valueField2 = null;string valueField3 = null; string body = null;XPathNavigator mds = MainDataSource.CreateNavigator(); EmailSubmitConnection esc;XPathNodeIterator xi = mds.Select("/my:myFields/my:myGroup/my:Field4", NamespaceManager);foreach (XPathNavigator xn in xi) { string valueField4 = xn.Value;if (valueField4 == "True") {valueField1 += mds.SelectSingleNode("/my:myFields/my:myGroup/my:Field1", NamespaceManager).Value + "\n"; valueField2 += mds.SelectSingleNode("/my:myFields/my:myGroup/my:Field2", NamespaceManager).Value + "\n";valueField3 += mds.SelectSingleNode("/my:myFields/my:myGroup/my:Field3", NamespaceManager).Value + "\n"; } }body = valueField1 + "\n" + valueField2 + "\n" + valueField3;esc = (EmailSubmitConnection)this.DataConnections["Email Submit"]; esc.Introduction = body; esc.Execute(); } } } 11-11-2009 03:31 PM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Custom coded C# email button issue Mark as Not AnswerMark as Answer... Reply Contact You are selecting the first row when you use: mds.SelectSingleNode("/my:myFields/my:myGroup/my:Field1", NamespaceManager).Value for example. Instead, you could use: xn.SelectSingleNode("../my:Field1", NamespaceManager).Value to get the value of Field1 for the same Group instance as the Field4 that is 'True'. Hilary Stoupa 11-11-2009 03:43 PM In reply to [email protected] Joined on 11-04-2009 Posts 12 Re: Custom coded C# email button issue Mark as Not AnswerMark as Answer... Reply Contact Sorry Hilary, Would this be what you mean?public void btnSend_Clicked(object sender, ClickedEventArgs e) { // Write your code here.string valueField1 = null; string valueField2 = null;string valueField3 = null; string subject = null;string body = null; XPathNavigator mds = MainDataSource.CreateNavigator();EmailSubmitConnection esc; XPathNodeIterator xi = mds.Select("/my:myFields/my:myGroup/my:Field4", NamespaceManager);foreach (XPathNavigator xn in xi) {string valueField4 = xn.Value;if (valueField4 == "true") { valueField1 += xn.SelectSingleNode("/my:myFields/my:myGroup/my:Field1", NamespaceManager).Value + "\n";valueField2 += xn.SelectSingleNode("/my:myFields/my:myGroup/my:Field2", NamespaceManager).Value + "\n";valueField3 += xn.SelectSingleNode("/my:myFields/my:myGroup/my:Field3", NamespaceManager).Value + "\n"; } } //subject = valueField1 + " " + valueField2;body = valueField1 + "\n" + valueField2 + "\n" + valueField3;esc = (EmailSubmitConnection)this.DataConnections["Email Submit"]; esc.Introduction = body; esc.Execute(); } 11-11-2009 04:37 PM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Custom coded C# email button issue Mark as Not AnswerMark as Answer... Reply Contact Well, not quite. You see, you are still using the full xpath, which takes you back to the first item. So instead of this: valueField1 += xn.SelectSingleNode("/my:myFields/my:myGroup/my:Field1", NamespaceManager).Value + "\n"; You'd want this: valueField1 += xn.SelectSingleNode("../my:Field1", NamespaceManager).Value + "\n"; Hilary Stoupa 11-12-2009 09:01 AM In reply to [email protected] Joined on 11-04-2009 Posts 12 Re: Custom coded C# email button issue Mark as Not AnswerMark as Answer... Reply Contact Hello again Hilary, Thank you very much that works! However, I've decided to make some changes. Instead of just email to the one that's being checked. I've added another checkbox whish will email to another person, & now it's not working on both. Here is my codepublic void btnSend_Clicked(object sender, ClickedEventArgs e) { // Write your code here.string valueField1 = null; string valueField2 = null;string valueField3 = null; string valueField4 = null;string valueField5 = null; //string subject = null;string body = null; XPathNavigator mds = MainDataSource.CreateNavigator();EmailSubmitConnection esc; XPathNodeIterator xi4 = mds.Select("/my:myFields/my:myGroup/my:Field4", NamespaceManager);XPathNodeIterator xi5 = mds.Select("/my:myFields/my:myGroup/my:Field5", NamespaceManager);foreach (XPathNavigator xn4 in xi4) { valueField4 = xn4.Value;if (valueField4 == "true") {valueField1 = xn4.SelectSingleNode("../my:Field1", NamespaceManager).Value; valueField2 = xn4.SelectSingleNode("../my:Field2", NamespaceManager).Value;valueField3 = xn4.SelectSingleNode("../my:Field3", NamespaceManager).Value;body += valueField1 + " " + valueField2 + " " + valueField3 + "\n"; } }foreach (XPathNavigator xn5 in xi5) { valueField5 = xn5.Value;if (valueField5 == "true") {valueField1 = xn5.SelectSingleNode("../my:Field1", NamespaceManager).Value; valueField2 = xn5.SelectSingleNode("../my:Field2", NamespaceManager).Value;valueField3 = xn5.SelectSingleNode("../my:Field3", NamespaceManager).Value;body += valueField1 + " " + valueField2 + " " + valueField3 + "\n"; } }if (valueField4 == "true") {esc = (EmailSubmitConnection)this.DataConnections["ToHim Email Submit"]; esc.Introduction = body; esc.Execute(); }if (valueField5 == "true") {esc = (EmailSubmitConnection)this.DataConnections["ToHer Email Submit"]; esc.Introduction = body; esc.Execute(); } } 11-12-2009 09:43 AM In reply to [email protected] Joined on 11-04-2009 Posts 12 Re: Custom coded C# email button issue Mark as Not AnswerMark as Answer... Reply Contact Hello Hilary, Once again, thank you for all the helps. I don't know if this is the best way, but it seems to work for me. Please feel free let me know if you have any better advice. Here is my code:public void btnSend_Clicked(object sender, ClickedEventArgs e) { // Write your code here.string valueField1 = null; string valueField2 = null;string valueField3 = null; string valueField4 = null; //string subject = null;string bodyTrue = null; string bodyFalse = null;XPathNavigator mds = MainDataSource.CreateNavigator(); EmailSubmitConnection escTrue = null;EmailSubmitConnection escFalse = null; XPathNodeIterator xi4 = mds.Select("/my:myFields/my:myGroup/my:Field4", NamespaceManager);foreach (XPathNavigator xn4 in xi4) { valueField4 = xn4.Value;if (valueField4 == "true") {escTrue = (EmailSubmitConnection)this.DataConnections["ToHim Email Submit"]; valueField1 = xn4.SelectSingleNode("../my:Field1", NamespaceManager).Value;valueField2 = xn4.SelectSingleNode("../my:Field2", NamespaceManager).Value; valueField3 = xn4.SelectSingleNode("../my:Field3", NamespaceManager).Value;bodyTrue += valueField1 + " " + valueField2 + " " + valueField3 + "\n"; }if (valueField4 == "false") {escFalse = (EmailSubmitConnection)this.DataConnections["ToHer Email Submit"]; valueField1 = xn4.SelectSingleNode("../my:Field1", NamespaceManager).Value;valueField2 = xn4.SelectSingleNode("../my:Field2", NamespaceManager).Value; valueField3 = xn4.SelectSingleNode("../my:Field3", NamespaceManager).Value;bodyFalse += valueField1 + " " + valueField2 + " " + valueField3 + "\n"; } }if (escTrue != null) { escTrue.Introduction = bodyTrue; escTrue.Execute(); }if (escFalse != null) { escFalse.Introduction = bodyFalse; escFalse.Execute(); } } Page 1 of 1 (8 items) Copyright © 2003-2019 Qdabra Software. All rights reserved.View our Terms of Use.
Hello All!
Wondering if anyone would be able to help me.
I've a simple form with a repeating table inside, there are only 4 columns.
The last column is a checkbox where if the box is checked, it'll send an email of the data on that row to someone when the button is clicked.
What it's happening right now is that, it only send the 1st row of data when I've about 4 out of 10 rows checked.
Any idea what I'm doing wrong?
Thank you very much in advance!
Hi:
Does the button have code on it to do this? Can you post your code?
Hello Hilary!
Thank you for your quick respond!
Here is the code:
using
{
}
valueField2 += mds.SelectSingleNode(
esc.Introduction = body;
esc.Execute();
You are selecting the first row when you use:
mds.SelectSingleNode("/my:myFields/my:myGroup/my:Field1", NamespaceManager).Value
for example. Instead, you could use:
xn.SelectSingleNode("../my:Field1", NamespaceManager).Value
to get the value of Field1 for the same Group instance as the Field4 that is 'True'.
Sorry Hilary,
Would this be what you mean?
valueField1 += xn.SelectSingleNode(
Well, not quite. You see, you are still using the full xpath, which takes you back to the first item. So instead of this:
valueField1 += xn.SelectSingleNode("/my:myFields/my:myGroup/my:Field1", NamespaceManager).Value + "\n";
You'd want this:
valueField1 += xn.SelectSingleNode("../my:Field1", NamespaceManager).Value + "\n";
Hello again Hilary,
Thank you very much that works!
However, I've decided to make some changes. Instead of just email to the one that's being checked.
I've added another checkbox whish will email to another person, & now it's not working on both.
Here is my code
valueField4 = xn4.Value;
valueField2 = xn4.SelectSingleNode(
valueField5 = xn5.Value;
valueField2 = xn5.SelectSingleNode(
Hello Hilary,
Once again, thank you for all the helps.
I don't know if this is the best way, but it seems to work for me. Please feel free let me know if you have any better advice.
Here is my code:
valueField1 = xn4.SelectSingleNode(
valueField3 = xn4.SelectSingleNode(
escTrue.Introduction = bodyTrue;
escTrue.Execute();
escFalse.Introduction = bodyFalse;
escFalse.Execute();