Udostępnij za pośrednictwem


More on Programmatically E-Mailing via InfoPath Code

Folks,

In this post https://blogs.msdn.com/timpash/archive/2005/11/03/Alternate_Ways_To_Send_Mail.aspx I was a bit lax in getting the novice to a 100% solution.   What I left out is that most often a user is going to want to pluck values out of the form and then use those values as recipients or in the text strings that comprise the body or the subject line.    The way you do that is by defining variables in the code, and then setting those variables to values in the XML from the main form.   For example, let's say you have a text field called username that is nested directly below MyFields in the datasource.    Using JScript you'd use a line like this to declare the variable and set the value:

var objUserName = XDocument.DOM.selectSingleNode("/my:myFields/my:username");

Then, later on in the code you'd do something like an objOutlookMsg.Receipts.Add(objUserName.text).

The idea is to set a variable to the node that you care about, then pull out the text attribute of the node when you need it.  Hope that's a little clearer!