Microsoft KB Archive/827002

= How to debug a script for a InfoPath form =

Article ID: 827002

Article Last Modified on 5/1/2007

-

APPLIES TO


 * Microsoft Office InfoPath 2007
 * 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

Office InfoPath 2007
In InfoPath 2007, you must first set the programming language that you want to use. Then, you must add the script.

Note JScript and VBScript programming examples are included in this article.

Set the programming language
Before you run this sample script in InfoPath 2007, you must change the programming language to VBScript or Jscript. To do this, follow these steps:

Warning The Remove Code command that is mentioned in the following steps removes all existing code from the current form. Therefore, do not use this option, unless you are sure that you want to perform this action.
 * 1) On the Tools menu, click Form Options.
 * 2) In the Category list, click Programming. If the Form template code language box is disabled, click Remove Code to remove all existing code in the form. If the Form template code language box is available, go to step 3.
 * 3) In the Form template code language box, click VBScript or Jscript, and then click OK.

Add the script
 On the Tools menu, point to Programming and then click On Load Event. Microsoft Visual Studio Tools for Applications starts.  Replace the OnLoad function by using the following JScript code or VBScript code as appropriate:

JScript function XDocument::OnLoad(eventObj) {       debugger; XDocument.UI.Alert(&quot;This is a test.&quot;); } VBScript Sub XDocument_OnLoad(eventObj) Stop XDocument.UI.Alert &quot;This is a test.&quot; End Sub  Save the changes, and then close Visual Studio Tools for Applications. On the Standard toolbar, click Preview. 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 script appears in Script Editor, and the script execution stops.

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

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

Microsoft Script Editor appears.</li>  Replace the OnLoad function with the following code:

JScript function XDocument::OnLoad(eventObj) {       debugger; XDocument.UI.Alert(&quot;This is a test.&quot;); } VBScript Sub XDocument_OnLoad(eventObj) Stop XDocument.UI.Alert &quot;This is a test.&quot; End Sub </li> Save the script, and then close Script Editor.</li></ol> </li> On the File menu, point to Preview Form, and then click Default.</li> 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 &quot;Install Web Script Debugging&quot; section.</li> Press F10 to move through the remaining lines of code in your script.</li></ol>

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 &quot;Add or Remove Features&quot; and change the feature to &quot;Run from My Computer&quot; or &quot;Run from CD/network&quot;.

Click OK, and then exit Script Editor.

To install the Web Debugging feature with Office Setup, follow these steps:

InfoPath 2007

 * 1) In Control Panel, open the &quot;Add or Remove Programs&quot; item.
 * 2) Select Microsoft Office in the list of installed programs, and then click Change.

Office Setup starts.
 * 1) Select Add or Remove Features in the list of maintenance mode options, and then click Next.
 * 2) Expand the Office Tools node.
 * 3) Expand the HTML Source Editing node.
 * 4) Expand the Web Scripting node.
 * 5) Click Web Debugging, and then click Run from My Computer.
 * 6) Click Continue.
 * 7) After the configuration is updated, click Close.

InfoPath 2003

 * 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.
 * 1) Select Add or Remove Features in the list of maintenance mode options, and then click Next.
 * 2) Select Choose advanced customization of applications, and then click Next.
 * 3) Double-click the Office Tools node.
 * 4) Double-click the HTML Source Editing node.
 * 5) Double-click the Web Scripting node.
 * 6) Select the drop-down menu for Web Debugging, and then click Run from My Computer.
 * 7) Click Update.

Additional query words: IP2007

Keywords: kbscript kbdebug kbappdev kbhowto kbcode KB827002

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.