Friday, January 30, 2009

Forms within Forms

An interesting InfoPath request; Quality has a project where I would like to use an InfoPath form for intakes. The idea is that the Intake form would be a form of forms where the user would launch each of the forms required for enrollment from a single master form. This form should be able to launch a blank copy of each of the enrollment forms, and this is the kicker, that follow “Paul’s Golden Rule” and avoid requiring any duplicate typing.

Launching a form is a point and click exercise, doing so while exposing the other forms fields requires a bit of code, but as it turns out, not much.

var newForm = Application.XDocuments.NewFromSolution(http://sharepoint/sites/it/area54/Sample Face Sheets/Forms/template.xsn);

var participant = newForm.DOM.selectSingleNode("my:FaceSheet/my:Client_Name");

myField = XDocument.DOM.selectSingleNode("my:myFields/my:Test");

participant.text = myField.text;

The first line launches the form, you’ll need the path to the form template, but that’s it. Your newForm variable then contains XDocument for the form just launched, in this case the face sheet. Now you can grab a field value from the parent form and copy it into the new form.

No comments: