One of the great and power features InfoPath provides is the xdExtension prefix. This feature allows your form to call into your code from areas like conditional formatting. It provides you with greater flexibility in determining the validity of a condition than is available from the InfoPath UI only.
Although xdExtension works in conditional formatting conditions, it doesn't work in rule conditions because the manifest.xsf file lacks a definition for the xdExtension namespace. Since rules are stored in the manifest, attempts to use xdExtension from a rule condition will fail. Fortunately we can fix this by manually updating the manifest.xsf file to include the appropriate namespace.
In this task we will manually add the xdExtension namespace to the manifest.xsf file so that we can call into code to determine rule conditions. We will then create a test rule that displays a success dialog box when our call succeeds. Let's start by designing a new blank form.
Modify the manifest.xsf file:
- In the designer, choose Extract Form Files from the File menu.
- Select a location to save your extracted form files to, and then click OK.
- Close InfoPath to release the lock it places on your form files.
- Using a text editor, open your manifest.xsf.
- Add the following namespace definition to the end of the xsf:xDocumentClass root element:
- Save the manifest.xsf file, and then close the text editor.
- Reopen your form template by right-clicking the manifest.xsf file and choosing Design.
Create the rule condition:
- Insert a button into the view
- Double-click the button.
- In the Button Properties dialog box, change the label to Test xdExtension.
- Click Rules, and then click Add.
- Name your rule Test xdExtension, and then click Set Condition.
- In the Condition dialog box, select The Expression in the first drop-down list.
- In the expression text box, type xdExtension:TestXdExtension().
You can set up your function to accept parameters if you desire and can pass them in from the condition expression.
- Click Add Action, and then select Show A Dialog Box Message in the Action drop-down list.
- Type Test Succeeded for the Message.
- Click OK four times to close all open dialog boxes.
Create the function to evaluate the rule condition:
- Press Alt+Shift+F11 to open the Microsoft Script Editor.
- Add the following function to your code:
return true; // Quick test to make sure xdExtension is working
- Close the Microsoft Script Editor.
This function must return a Boolean value. A return value of true is required for the rule actions to be processed.
- Preview your form.
- Click the button you inserted into the view.
At this point your rule calls into the TestXdExtension function, which returns true. This causes the dialog box message to appear stating that the test succeeded.
©2004 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.