views:

355

answers:

1

I'm trying to build an InfoPath add-in to allow template editors (as opposed to end users) to preview the form with sample data populated.

First, a little background on our environment. We have a custom process that connects to MOSS, downloads the appropriate datasource assemblies for a given form, and invokes them to load data from the database into the form (such as recipient address information in a letter template). This process is launched when the form is downloaded and passed parameters (via the URL) for the data retrieval. I am able to approximate this behavior by passing parameters to a locally saved form template via the command line.

Armed with that knowledge, I set out to build an InfoPath add-in that would do the following:

  1. Display a custom toolbar button in Design mode that the template editor can click to populate the form with sample data (requires parameters to be passed).
  2. When the button is clicked, save a copy of the active template to a temp folder and use the Shell() command to pass parameters to the form. The copy of the form would then be launched in a separate InfoPath window.

I referred to various online tutorials and Apress' Pro InfoPath 2007 for guidance along the way, and like previous posts on here, discovered the information available to be very limited. I'm part way there, but ran into a few issues:

  1. I was able to get the custom toolbar button to show up, but only in Preview mode. I need the button to show up in Design mode.
  2. The Application.ActiveWindow.XDocument.SaveAs() method appears to save only the form, not the entire template. Perhaps this is because I am in Preview mode rather than Design mode? Maybe addressing the first issue will resolve this as well.
  3. In an effort to avoid the two issues above, I looked into how I might call the FormEvents_Loading handler in my form template solution. This would allow me to pass it the test parameters without having to resort to saving a copy and launching it via the command line. I could not figure out how to do this.

Any ideas or suggestions? Thanks in advance for your help!

A: 

Are you aware of the Form Options -> Preview tab? In there you can set a form to use when previewing the template. It sounds like this is what you are looking to do. Possibly use the addin to modify a default preview form and then the user simply clicks preview to see your sample data.

oillio
The Form Options > Preview tab would give me the functionality I want, but would require specifying test data for every form we have (> 200). I ended up modifying my datasource assemblies to use default values when no parameters are passed. Since the datasource code executes when the form launches already, clicking the Preview button now loads default data into the form.
Andrew Dyer