How-to Debug MS Script (JScript) in MS InfoPath 2003

on October 27, 2006

This article as two parts. This one shows how to debug MS Script (JScript) in MS InfoPath. The second one, provide the information to submit a newly completed form to a Document Library (Form Library) in Sharepoint.

Part Two is overhere:
http://www.e-soft.ca/blogs/index.php?title=how_to_submit_an_infopath_form_to_a_wind&more=1&c=1&tb=1&pb=1

Note that most of what you’ll read comes from MSDN, but with added code and comments.

Before going any further, I have to warn you about a possible failure with the MS Script Editor. If it crashes every time you try to open the code (the editor) you may encounter the same problem I had. It is caused by splitted Office Software installation. I won’t go into a lot of detail on the « Why », but just let you know that it can be fixed by running the MS Office Setup again and doing a Reinstall.

If you want to read mroe about it, see the KB article 898789:
http://support.microsoft.com/kb/898789/en-us?spid=2515&sid=251

So here is How-to Debug…

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:
a. On the Tools menu, point to Script, and then select On Load Event.
Microsoft Script Editor appears.
b. Add “debugger;” to the OnLoad function. See the following code:

JScript

Code:

ode>function XDocument::OnLoad(eventObj)
{
debugger;
}

VBScript

Code:

ode>Sub XDocument_OnLoad(eventObj)
Stop
XDocument.UI.Alert "This is a test."
End Sub

c. Save the script, and then close Script Editor.

NOTE: This will make the debugger to stop at the beginning of the code execution. If you want to step directly to another part of your code, add “debugger;” at the line you want the debugger to stop.

This way, you can hit F5 after the debugger open on the first debugger line. Or as for Visual Studio, use F10, F11 etc. You’ll be able to see the variable values by doing onMouseOver.

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.

One last detail, “Comment” you debugger lines when you’re done. Because it would be compiled as an error when someone fill a new form.

Enjoy!

ShareThis