This article describes how to use a script for a conditional formatting expression and how to use a field in a secondary data source for a conditional formatting expression. You use either the script or the field in the secondary data source in a Microsoft Office InfoPath 2007 form or in a Microsoft Office InfoPath 2003 form.
To use either a script function with conditional formatting or a secondary data source field with conditional formatting, you select the expression for the condition type.
An expression that references a field in a secondary data source has syntax that is similar to the following:
DataSourceName refers to the name that you give to the secondary data source.
•
docRoot is the XML document root.
•
Node1 and Node2 are nodes that are contained in the XML. Node2 is a child of Node1.
•
my:myField1 refers to a field in the primary data source of your form.
In this particular example, the conditional formatting statement checks the text value of Node2 in the secondary data source against my:myField1 in the main data source, and then applies the format that you selected if the two values match.
Similarly, to call a script function from the conditional formatting expression, you can use the xdExtension prefix that is bound to the http://schemas.microsoft.com/office/infopath/2003/xslt/extension namespace.
On the Tools menu, point to Script, and then click Microsoft Script Editor.
2.
Add the following function to the code window:
function CheckItem()
{
return "Airfare";
}
3.
Save the script, and then close Script Editor.
4.
On your form, right-click the text box for the ExpenseName field, and then click Text Box Properties.
5.
In the Text Box Properties dialog box, click the Display tab, and then click Conditional Formatting.
The Conditional Formatting dialog box appears.
6.
Click Add.
The Conditional Format dialog box appears.
7.
In the Conditional Format dialog box, select the expression from the drop-down list, and then type the following condition in the text box:
my:ExpenseName = xdExtension:CheckItem()
Click Bold, and then click OK.
8.
Click OK to close the Conditional Formatting dialog box.
9.
Click OK to close the Text Box Properties dialog box.
10.
Click Preview Form. To test the form, follow these steps:
a.
Enter the expense name Lodging. Enter the amount 250.
b.
Press CTRL+ENTER to add a new row.
c.
Enter the expense name Airfare. Enter the amount 700.
Note Only the expense name on the second row is bold because the expense name equals Airfare, and Airfare is the text value that is returned from the CheckItem function.
For InfoPath 2007
1.
On the Tools menu, point to Programming, and then click Microsoft Script Editor.
2.
Add the following function to the code window.
function CheckItem()
{
return "Airfare";
}
3.
On the File menu, click Save.
4.
On the File menu, click Exit.
5.
On the form, right-click the text box for the ExpenseName field, and then click Text Box Properties.
6.
In the Text Box Properties dialog box, click the Display tab, and then click Conditional Formatting.
The Conditional Formatting dialog box appears.
7.
Click Add.
The Conditional Format dialog box appears.
8.
In the Conditional Format dialog box, click the expression in the list, and then type the following condition in the box:
my:ExpenseName = xdExtension:CheckItem()
9.
Click Bold, and then click OK.
10.
To close the Conditional Formatting dialog box, click OK.
11.
To close the Text Box Properties dialog box, click OK.
12.
On the File menu, click Preview, and then click Form.
13.
To test the form, follow these steps:
a.
Enter the expense name Lodging.
b.
Enter the amount 250.
c.
To add a new row, press CTRL+ENTER.
d.
Enter the expense name Airfare.
e.
Enter the amount 700.
Note Only the expense name on the second row is bold because the expense name equals Airfare, and Airfare is the text value that is returned from the CheckItem function.
Need More Help? Contact a Support professional by Email, Online or Phone.
Customer Service For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
Newsgroups Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.