Emailing a different InfoPath form
I recently needed to create an InfoPath form that enabled the user to post the data to another user in a format they could open in *their* InfoPath form. After some thought, I went with the idea of running an XSL transform on the data and posting it via an email connector.
Of course, first I needed to create the XSLT. Obviously you can do this in notepad, but I prefer tools that are less likely to make my eyes bleed. I chose to go with Altova's MapForce - it's a great visual designer for mapping one schema to another:
I extracted the form files from each InfoPath form and loaded the myschema.xsd files as source and destination. MapForce handled most of the mapping, connecting similarly-named nodes. Then I generated the XSLT. I had to do a quick edit on the XSL to provide the processing instructions and pull out the schemaLocation attribute on the root. (You can probably do this in MapForce too, but I was in a rush...)
So, next thing - add the xslt to the form as a data connection. You want to create a data connection that will Receive Data from an XML file - then you can select your XSLT file and add it as a resource.
Now create a data connection to submit the form via email - set properties as needed.
Add a button and add form code - I'm working in jscript so that I didn't need a fully trusted form.
The final step, add the following code:
//Get the current form data
//Get the transform
//Initialize the final xml DOM
var tmpDOM=new ActiveXObject("MSXML2.DomDocument.5.0");
//Perform the transform; strDOM gets the XML String
//Load the XML String from above into our DOM variable
//Post the DOM via email.