Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to debug a script for a InfoPath form


View products that this article applies to.

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.

↑ Back to the top


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

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
  1. On the Tools menu, point to Programming and then click On Load Event. Microsoft Visual Studio Tools for Applications starts.
  2. Replace the OnLoad function by using the following JScript code or VBScript code as appropriate:

    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 changes, and then close Visual Studio Tools for Applications.
  4. On the Standard toolbar, click Preview.
  5. 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.
  6. Press F10 to move through the remaining lines of code in the script.

InfoPath 2003

  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:

InfoPath 2007

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

    Office Setup starts.
  3. Select Add or Remove Features in the list of maintenance mode options, and then click Next.
  4. Expand the Office Tools node.
  5. Expand the HTML Source Editing node.
  6. Expand the Web Scripting node.
  7. Click Web Debugging, and then click Run from My Computer.
  8. Click Continue.
  9. 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.
  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.

↑ Back to the top


Keywords: kboffice12vista, kboffice12yes, kbfreshness2006, kbsweptinfopath2003sp1, kbsweptsoltax, kbscript, kbdebug, kbappdev, kbhowto, kbcode, kb

↑ Back to the top

Article Info
Article ID : 827002
Revision : 3
Created on : 4/17/2018
Published on : 4/19/2018
Exists online : False
Views : 591