Functions (also known as "xpath functions") are used when writing advanced logic inside a form, display conditions for a form or a case list filter.  Functions can take some information, process it and return a value.  

Function names are case-sensitive.  I.e. if you want to use the function today(), you cannot type Today() or TODAY().  

Direct Values

These functions directly return a value with no arguments.  

true

false

today

now

here

Formatting/Conversion Functions

These functions help convert one value into a value of another type.  (ex. converting a string value into a date value).  

boolean

boolean-from-string

number

int

double

string

date

 

format-date

There are also uses of format-date() which can format dates to be appropriate for alternate calendars, such as the Nepali or Amharic calendars. More detail can be found at Alternate Calendar Formats for CommCare Android.

Logic and Math

+

-

*

  • BehaviorSimple multiplication between two values
  • Return: Returns the product of the two values
  • Arguments:  Two numbers
  • Syntax: x * y.
  • Example: '6 * 6' returns 36.  Many common uses.

div

  • BehaviorSimple division between two values
  • Return: Returns the quotient of the two values
  • Arguments:  Two numbers
  • Syntax: x div y.
  • Example: '15 div 2' returns 7.5.  Many common uses.

not

mod

if

cond

random

count

sum

min

max

regex

uuid()

uuid(argument)

coalesce

depend

checklist

weighted-checklist

pow

exp

pi

sqrt

log

log10

abs

ceiling

floor

round

distance

acos

asin

atan

cos

sin

tan

String Functions

 

concat

contains

ends-with

join

lower-case

replace

starts-with

substr

string-length

selected-at

translate

upper-case

substring-before

substring-after

sort

sort-by

Multi-Select Helper Functions

These functions are useful for working with a multi-select question. Multi-select questions store what is selected as a space-separated list of items. These functions will operate over that space separated list.  

selected

count-selected

selected-at