Functions in InfoPath

A function is a predefined expression that returns a value based on the results of a calculation. For example, a function might return the current date and time or it might return the sum of all values stored in a repeating field.

To use a function in a form, you include it in a formula, which is an XPath (XML Path Language (XPath): A language used to address parts of an XML document. XPath also provides basic facilities for manipulation of strings, numbers, and Booleans.) expression that consists of arguments, such as values or fields, operators, and functions. You might use a formula to display the date and time, reference fields in a form, calculate mathematical values, or perform string operations such as combining multiple fields into one field. Formulas are stored in fields and formula results are displayed in the controls that are bound (bind: To connect a control to a field or group in the data source so that data entered into the control is saved. When a control is unbound, it is not connected to a field or group, and so data entered into the control will not be saved.) to those fields. You can add a formula to a field by setting either the control's properties (for text boxes, rich text boxes, and date pickers) or the field's properties.

The following tables list the functions that are available in InfoPath.

Date and time functions

Function Description Example
now Returns the current date and time. No argument is required. now()
today Returns the current date. No argument is required. today()

Field functions

Function Description Example
count Counts the number of instances of the specified field or group. count (field1)
id Returns the fields or groups associated with the specified ID. This function is not available in the Insert Function dialog box; it must be typed in the Formula box in the Insert Formula dialog box. id(field1)
last Returns the value of the last occurrence of the field in the current context. field1[last()]
local-name Returns the name of the specified field or group. If the argument is a set of fields or groups, it returns the name of the first field or group. local-name(field1)
name Returns the name of the specified field or group, as well as its namespace prefix. If the argument is a set of fields or groups, it returns the name and prefix of the first field or group. name(field1)
namespace-uri Returns the full namespace of the specified field or group. If the argument is a set of fields or groups, it returns the namespace of the first field or group. namespace-uri(field1)
position Returns the index (or position) of the field or group with respect to the other fields and groups in the same group. position()
current Returns the current field or group in a repeating context. You can use the current function to refer to a current row in a repeating table or repeating section within a larger expression. current()

Math functions

Formulas that contain mathematical functions usually require arguments that are integer or decimal values. To ensure that arguments are integer or decimal values, instead of null values, select the Treat blank values as zero check box on the General tab in the Form Options dialog box (Tools menu).

Function Description Example
avg Calculates the average value of all of the numerical values in the argument. avg(field1)
Boolean Returns true if the argument is not null, is a positive or negative number, or is a non-empty string. Otherwise, returns false. Returns false if the argument is null, is zero or an NaN value, or is an empty string. boolean(field1)
ceiling Returns the smallest integer that is not less than the argument (rounding up). ceiling(field1)
eval Returns the values of a set of fields. The first argument defines the set of fields; the second argument defines the expression to calculate for the set of fields. Usually, the eval function is nested within a function that operates on a set of fields, such as sum or avg. sum(eval(group2, "field1 * field2"))
false Returns false. false()
floor Returns the largest integer that is not greater than the argument (rounding down). floor(field1)
max Returns the largest number in the argument. max(field1)
min Returns the smallest number in the argument. min(field1)
not Returns true if the argument is false or null. Returns false if the argument is true or not null. not(field1)
number Converts the argument into a number. number(field1)
nz Returns the value of the specified field. If the field is blank, it returns zero (0). nz(field1)
round Rounds the argument to the nearest integer. round(field1)
sum Calculates the sum of the arguments. sum(field1)
true Returns true. true()

Text functions

Function Description Example
concat Combines the value of fields with other fields or text strings. concat(field1," of ",field2)
contains Returns true if the first argument contains the second argument. Otherwise, it returns false. contains(field1, "city")
normalize-space Removes the white space from the argument. normalize-space(field1)
starts-with Returns true if the first argument starts with the second argument. Otherwise, it returns false. starts-with(field1, "B")
string Converts the argument to a text string. string(field1)
string-length Returns the number of characters in the argument. string-length(field1)
substring Returns a specific part of a text string. The first argument defines the text string, the second argument defines the starting position, and the third argument defines how many characters to include. substring(field1, 3,5)
substring-after Returns a specific part of a text string. The first argument defines the text string, and the second argument defines what to look for in the text string. The function returns the text that follows the first occurrence of the second argument. substring(field1, "country")
substring-before Returns a specific part of a text string. The first argument defines the text string, and the second argument defines what to look for in the text string. The function returns the text that precedes the first occurrence of the second argument. substring-before(field1, "the end")
translate Returns a converted text string. The first argument defines the text string, the second argument defines the characters to change in the text string, and the third argument defines what to change the characters to. The characters in the second argument are converted to the characters in the third argument's matching position. translate(field1, "()","[]")
 
 
Applies to:
InfoPath 2003