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
var CurrentForm=XDocument.DOM;


//Get the transform
var XSLTFileDOM=XDocument.GetDOM(“MTCXSLT”);
 
//Initialize the final xml DOM
var tmpDOM=new ActiveXObject(“MSXML2.DomDocument.5.0”);
tmpDOM.validateOnParse=true;
tmpDOM.async=false;


//Perform the transform; strDOM gets the XML String
var strDOM=CurrentForm.transformNode(XSLTFileDOM);


//Load the XML String from above into our DOM variable
tmpDOM.loadXML(strDOM);


//Post the DOM via email.
XDocument.DataAdapters(“SubmitToMTC”).SubmitData(tmpDOM);


Voila!


Philo

Comments (2)

  1. MSDNArchive says:

    Excellent post. Any chance of posting a close-up?

  2. MSDNArchive says:

    I’ll have to dig around to a different place to stash images – TextAmerica keeps squishing them down.

    In the meantime, the image is a basic mapper – schemas on each side, lines between mapping node to node. You can download a trial version of MapForce from Altova. Obviously for more industrial uses or if this is a recurring need you’ll want to use something like BizTalk to manage translation and routing.

    Philo