How to use a script or a secondary data source field for conditional formatting in InfoPath 2003 (827008)
The information in this article applies to:
- Microsoft Office InfoPath 2003
- Microsoft Office InfoPath 2003, Service Pack 1 (SP1)
SUMMARYThis 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 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: xdXDocument:GetDOM(' DataSourceName')/ docRoot/ Node1/ Node2 = my:myField1In this syntax, the placeholders are: - 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. back to the topDesign a New FormThis example describes how to create a conditional format that uses both expression types. - Start InfoPath. Design a new, blank form.
- Select the Data Source task pane. To add fields to your form, follow these steps:
- In the Data Source task pane, right-click myFields, and then click Add.
- In the Add Field or Group dialog box, type myExpenses. In the Type drop-down list, select Group. Select the Repeating option, and then click OK.
- In the Data Source task pane, right-click myExpenses, and then click Add.
- In the Add Field or Group dialog box, type ExpenseName, and then click OK.
- In the Data Source task pane, right-click myExpenses, and then click Add.
- In the Add Field or Group dialog box, type ExpenseValue. In the list of data types, select Decimal (double), and then click OK.
- Move the myExpenses group in the Data Source task pane to your form, and then click Repeating Table.
back to the topUse a Script for Conditional Formatting- On the Tools menu, point to Script, and then click Microsoft Script Editor.
- Add the following function to the code window:
function CheckItem()
{
return "Airfare";
} - Save the script, and then close Script Editor.
- On your form, right-click the text box for the ExpenseName field, and then click Text Box Properties.
- In the Text Box Properties dialog box, click the Display tab, and then click Conditional Formatting.
The Conditional Formatting dialog box appears. - Click Add.
The Conditional Format dialog box appears. - 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. - Click OK to close the Conditional Formatting dialog box.
- Click OK to close the Text Box Properties dialog box.
- Click Preview Form. To test the form, follow these steps:
- Enter the expense name Lodging. Enter the amount 250.
- Press CTRL+ENTER to add a new row.
- 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 (the text value that is returned from the CheckItem function).
back to the topUse a Field in a Secondary Data Source for Conditional Formatting- Use an XML editor or a text editor such as Notepad to create an XML file with the following contents:
<?xml version="1.0"?>
<ExpenseRequirements>
<RequiresReceipt>75.00</RequiresReceipt>
</ExpenseRequirements> Name the file ExpenseRequirements.xml. - To add ExpenseRequirements.xml as a secondary data source for your form, follow these steps:
- On the Tools menu, click Secondary Data Sources.
The Secondary Data Sources dialog box appears. - Click Add.
The Data Source Setup Wizard appears. - Select XML data file for your data source, and then click Next.
- Click Browse.
The Open dialog box appears. - Move to ExpenseRequirements.xml, and then click Open.
- Click Next, and then click Finish to complete the Data Source Setup Wizard. When prompted to add the file to your form, click Yes.
- In the Secondary Data Sources dialog box, click Close.
- Right-click the repeating table on your form, and then click Repeating Table Properties.
- In the Repeating Table Properties dialog box, select the Display tab, and then click Conditional Formatting.
The Conditional Formatting dialog box appears. - Click Add.
The Conditional Format dialog box appears. - In the Conditional Format dialog box, select the expression in the drop-down list. Type the following condition in the text box:
my:ExpenseValue > xdXDocument:GetDOM("ExpenseRequirements")/ExpenseRequirements/RequiresReceipt
In the Background Color drop-down list, select the color red, and then click OK. - Click OK to close the Conditional Formatting dialog box.
- Click OK to close the Repeating Table Properties dialog box.
- Click Preview Form.
- To test the form, follow these steps:
- Enter the expense name Lunch. Enter the amount 25.
- Press CTRL+ENTER to add a new row.
- Enter the expense name Dinner. Enter the amount 80.
Note Only the second row is formatted with a red background because the expense value exceeds 75.
back to the top
Modification Type: | Minor | Last Reviewed: | 8/19/2004 |
---|
Keywords: | kbHOWTOmaster KB827008 kbAudDeveloper |
---|
|
|
©2004 Microsoft Corporation. All rights reserved.
|
|