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
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.
- On the Tools menu, click Form Options.
- 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.
- 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:
JScriptfunction XDocument::OnLoad(eventObj)
{
debugger;
XDocument.UI.Alert("This is a test.");
}
VBScriptSub XDocument_OnLoad(eventObj)
Stop
XDocument.UI.Alert "This is a test."
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 "Install Web Script Debugging" section. - Press F10 to move through the remaining lines of code in the script.
InfoPath 2003
- Start Infopath 2003.
- On the File menu, click Design a Form.
- In the Design a Form task pane, click New Blank Form.
- 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. - Replace the OnLoad function with the following code:
JScriptfunction XDocument::OnLoad(eventObj)
{
debugger;
XDocument.UI.Alert("This is a test.");
}
VBScriptSub XDocument_OnLoad(eventObj)
Stop
XDocument.UI.Alert "This is a test."
End Sub
- Save the script, and then close Script Editor.
- On the File menu, point to Preview Form, and then click Default.
- 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. - 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:
InfoPath 2007
- In Control Panel, open the "Add or Remove Programs" item.
- Select Microsoft Office in the list of installed programs, and then click Change.
Office Setup starts. - Select Add or Remove Features in the list of maintenance mode options, and then click Next.
- Expand the Office Tools node.
- Expand the HTML Source Editing node.
- Expand the Web Scripting node.
- Click Web Debugging, and then click Run from My Computer.
- Click Continue.
- After the configuration is updated, click Close.
InfoPath 2003
- In Control Panel, select Add or Remove Programs.
- Select Microsoft Office in the list of installed programs, and then click Change.
Office Setup begins. - Select Add or Remove Features in the list of maintenance mode options, and then click Next.
- Select Choose advanced customization of applications, and then click Next.
- Double-click the Office Tools node.
- Double-click the HTML Source Editing node.
- Double-click the Web Scripting node.
- Select the drop-down menu for Web Debugging, and then click Run from My Computer.
- Click Update.