How to debug a script for a Microsoft Office InfoPath 2003 form (827002)



The information in this article applies to:

  • Microsoft Office InfoPath 2003
  • Microsoft Office InfoPath 2003, Service Pack 1 (SP1)

SUMMARY

This article describes how to stop code execution in an InfoPath form. You want to do this so that you can debug a script for an InfoPath form.

MORE INFORMATION

To debug a script for an InfoPath form, you must first attach Microsoft Script Debugger to your InfoPath form. When Script Debugger debugs script for an InfoPath form, breakpoints are not recognized. Therefore, code execution does not stop at breakpoints. Instead of breakpoints, you must use the Microsoft JScript DEBUGGER statement (or the Microsoft Visual Basic Scripting [VBScript] STOP statement) to stop code execution for debugging purposes.

For additional information about how to stop code execution for debugging with JScript and with VBScript and about how to change the script language for your InfoPath form to VBScript or to JScript, click the following article number to view the article in the Microsoft Knowledge Base:

828853 How to change the script language for your InfoPath form

Step-by-Step

  1. Start Infopath 2003.
  2. On the File menu, click Design a Form.
  3. In the Design a Form task pane, click New Blank Form.
  4. To add the following script to your form, follow these steps:
    1. On the Tools menu, point to Script, and then select On Load Event.

      Microsoft Script Editor appears.
    2. Replace the OnLoad function with the following code:

      JScript
      	function XDocument::OnLoad(eventObj)
      	{
      		debugger;
      		XDocument.UI.Alert("This is a test.");
      	}
      VBScript
      	Sub XDocument_OnLoad(eventObj)
      		Stop
      		XDocument.UI.Alert "This is a test."
      	End Sub
    3. Save the script, and then close Script Editor.
  5. On the File menu, point to Preview Form, and then click Default.
  6. The Just-In-Time Debugging dialog box appears. Select New Instance of Microsoft Script Editor in the list of possible debuggers, and then click Yes.

    The Step Into Remote Procedure Call dialog box appears. Click OK.

    Your script appears in Script Editor, and the script execution stops.

    Note If Script Editor appears but your code does not appear, then you may have to install the Web Debugging feature for Script Editor. For details, see the following "Install Web Script Debugging" section.
  7. Press F10 to move through the remaining lines of code in your script.

Install Web Script Debugging

When try to debug your script, if Script Editor opens, but your code does not appear in the Code window, click the Debug menu, and then click Install Web Debugging. If the Web Debugging feature was marked install-on-demand during Office Setup, you receive the following error message:
Installing the Web Debugging feature will require you to restart the Microsoft Script Editor. This feature is not currently installed. Would you like to install it now?
Click Yes to install Web Debugging. After installation, you must close Preview mode, and then you must start Preview mode again to debug your script.

If the Web Debugging feature was marked not installed during Office Setup, you receive the following error message:
Installing the Web Debugging feature will require you to restart the Microsoft Script Editor. This feature is not available. To make this feature available, please run Setup again, select "Add or Remove Features" and change the feature to "Run from My Computer" or "Run from CD/network".
Click OK, and then exit Script Editor.

To install the Web Debugging feature with Office Setup, follow these steps:
  1. In Control Panel, select Add or Remove Programs.
  2. Select Microsoft Office in the list of installed programs, and then click Change.

    Office Setup begins.
  3. Select Add or Remove Features in the list of maintenance mode options, and then click Next.
  4. Select Choose advanced customization of applications, and then click Next.
  5. Double-click the Office Tools node.
  6. Double-click the HTML Source Editing node.
  7. Double-click the Web Scripting node.
  8. Select the drop-down menu for Web Debugging, and then click Run from My Computer.
  9. Click Update.

Modification Type:MinorLast Reviewed:8/19/2004
Keywords:kbScript kbDebug kbAppDev kbhowto kbcode KB827002 kbAudDeveloper