Use Code to Determine a Rule Condition - Greg Collins

InfoPath Dev

This Blog


Greg Collins

Use Code to Determine a Rule Condition

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:

  1. In the designer, choose Extract Form Files from the File menu.
  2. Select a location to save your extracted form files to, and then click OK.
  3. Close InfoPath to release the lock it places on your form files.
  4. Using a text editor, open your manifest.xsf.
  5. Add the following namespace definition to the end of the xsf:xDocumentClass root element:


  1. Save the manifest.xsf file, and then close the text editor.
  2. Reopen your form template by right-clicking the manifest.xsf file and choosing Design.

Create the rule condition:

  1. Insert a button into the view
  2. Double-click the button.
  3. In the Button Properties dialog box, change the label to Test xdExtension.
  4. Click Rules, and then click Add.
  5. Name your rule Test xdExtension, and then click Set Condition.
  6. In the Condition dialog box, select The Expression in the first drop-down list.
  7. 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.

  1. Click Add Action, and then select Show A Dialog Box Message in the Action drop-down list.
  2. Type Test Succeeded for the Message.
  3. Click OK four times to close all open dialog boxes.

Create the function to evaluate the rule condition:

  1. Press Alt+Shift+F11 to open the Microsoft Script Editor.
  2. Add the following function to your code:

function TestXdExtension()
    return true; // Quick test to make sure xdExtension is working

  1. 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.

Try It:

  1. Preview your form.
  2. 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



Terry G Phillips said:

IP2007 - I'm having a failure in my function while trying to call a DataConnection.Execute(). Is it even possible to do this?

May 7, 2007 6:27 PM

jatuphum said:


I use Infopath 2007. I designed my template such as "my template.xsn" but It doesn't "manifest.xsf"

And I do your solution with "my template.xsn" but not "manifest.xsf"

When I preview "my template.xsn", error this occurs



That assembly does not allow partially trusted callers.

Error occurred during a call to property or method 'TestAlert'.


How can I fix it?, and how about different between ".xsn" and ".xsf"?

Thank you.

October 8, 2007 3:50 AM

jatuphum said:

Expansion for above comment,

I forgot to tell you about my managed code I use VSTA to write code for "my template.xsn". And function "TestAlert" is in it.

Thank you.

October 8, 2007 4:09 AM

Greg Collins said:


The XSN is a collection of files, which includes the .xsf file. You must expand it (File menu of the designer) to get to the files it contains.

January 18, 2008 4:09 PM

jlricher said:


I have a IP2007 browser-enabled form, and i'm trying to use the xdExtension to run some code. I've check the manifest.xsf and the xdExtension namespace is there. At the update of the form, on the form server, I have an error about xdExtension namespace within the manifest.xsf. Do you know what can possibly cause this ?


January 24, 2008 12:53 PM

infopathcole said:

I have a problem with passing parameters to the function. Apparently the parameter being passed to the function is type "system._object". I have been scratching my head with this and going no where. Here's a sample code:

function getGradingPolicy(sqrFoot, TotInfraction)


   if (sqrFoot > 10)

       return "BIG"


       return "small";


I'm calling the script from infopath rule  like this:

xdExtension:getGrading(sqrfoot, totinfraction)

How can I cast a type "system._object" into integer?

Thanks for your help.

January 28, 2008 12:03 PM

infopathcole said:

Solved my problem.

In manifest.xsf don't do this:

xdExtension:getGradingPolicy(../my:SquareFootage, ../my:TotalInfraction)

Do this:

xdExtension:getGradingPolicy(number(../my:SquareFootage), number(../my:TotalInfraction))

January 28, 2008 3:07 PM
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.