Report expressions

The response to a question can be displayed in a report template by providing its name enclosed in curly brackets {}, and preceded by a dollar sign. Any string value included in an expression must be enclosed in double quotes.

The following example displays the response from a text question called firstname:

${firstname}

In addition to displaying the response to a question in a report, keywords can be used to display other useful information. The following displays the current date and time when printing a report:

${$date}

If the result is an array, the array can be iterated using # as a start tag and / as an end tag within the curly brackets. The following prints all image files on separate lines:

${#image1}
${$file}
${/}

You can also use expressions to refine how responses are displayed. An expression can be a single question name or keyword (as above), a calculation involving one or more questions or keywords, or a question name or keyword with methods and parameters to constrain or apply style to the response. An expression uses the following notation:

${questionname or keyword | method:parameter}

An expression can include multiple methods and parameters or none at all. Parameters can be either values from other questions or a fixed value.

The following expression displays the calculation of a number question named floweringtrees divided by a number question named totaltrees. When referring to multiple questions in the same expression, the individual question names only need to be directly named and do not need additional curly brackets:

${floweringtrees / totaltrees}

The following expression displays the x-coordinate value from the location question in which getValue is the method and x is the parameter:

${location | getValue:"x"}

The following expression evaluates as true if the response to a question named fruitcolor is not equal to red:

${if fruitcolor!="red"}The fruit is not red.${/}

Strings can be concatenated in an expression by joining them with a plus sign. The following expression uses this concatenation to pass the contents of a question named field_0 to a QR code-generating service, creating a QR code for the question's response:

${$image | src:"https://barcode.tec-it.com/barcode.ashx?code=QRCode&data="+field_0}

Example expressions for each type of question, are available in the following topics:

Expression methods

Not all question types support expressions and methods. The following table lists the methods and parameters you can use with various question types:

MethodParameterConnect question typeWeb designer question typeDescription

getValue

-

All question types

All question types

Retrieves the raw data value from the feature layer or raw image from an attachment.

getValue

x, y, z, wkid

geopoint

Map

Retrieves the x-, y-, z-coordinates individually in a specified spatial reference. The wkid parameter is optional, and its value is the same as the spatial reference of the feature layer if omitted.

getValue

length, area, unit, measurement type

geotrace, geoshape

Map

Returns the length of a polyline or the perimeter or area of a polygon, in given units and specifies whether the measurements are planar or geodesic. The default measurement type is geodesic.

getValue

name, size

image, audio, file

Image, Signature, Audio, File

Returns the file name or size of an attachment.

getValue

width, height, x, y, date, time, direction

image

Image, Signature

the width and height return the integer value of the image width and height in pixels, and x, y, date, time, and direction return values read from the image EXIF if present.

getValue

count

begin repeat, image, audio, file

Repeat, Image, Signature, Audio, File

Returns the total count of repeats or attachments.

getValue

position

begin repeat, image, audio, file

Repeat, Image, Signature, Audio, File

Returns an integer equal to the 1-indexed position in the array.

getValue

duration

audio, file

Audio, File

Returns the length of audio recordings in seconds.

Caution:

Duration is not returned in responses collected in the web app when using Safari.

appearance

multiline

text

Multiline text

Retains the line breaks in the string. If no appearance value is specified, a single line string is returned.

appearance

bullets

select_multiple

Multiple select

Returns answer in bullet format.

checked

choice name

select_one, select_multiple

Multiple select, Single select, Single select grid, Dropdown, Likert scale, Rating

Returns a checked check box if the field value equals the choice name; otherwise, returns an unchecked check box.

selected

choice name

select_one, select_multiple

Multiple select, Single select, Single select grid, Dropdown, Likert scale, Rating

If a coded value domain exists, returns true if the field value equals the choice name; otherwise, returns false.

countSelected

-

select_one, select_multiple

Multiple select, Single select, Single select grid, Dropdown, Likert scale, Rating

Returns the number of selected choices.

selectedAt

index

select_one, select_multiple

Multiple select, Single select, Single select grid, Dropdown, Likert scale, Rating

Returns the string at the index position in the choice list. The index starts at zero.

locale

language code

date, dateTime, start, end, decimal

Date, Date and time, Number

Returns the localized date, time, and number.

format

format string

date, dateTime, integer, decimal, start, end

Date, Date and time

Returns a formatted date string.

utcOffset

offset value

date, dateTime, start, end

Date, Date and time

Returns a date or date-time value that is shifted by the UTC offset value.

mapSettings

web map item ID, map scale

geopoint, geotrace, geoshape

Map

Specifies the basemap and scale when printing the map image.

Legacy:

This method has been replaced by map and mapScale.

mapExtent

xmin, ymin, xmax, ymax, wkid

geopoint, geotrace, geoshape

Map

Specifies the fixed map extent when printing the map image. The wkid parameter is optional and is set to 4326 (WGS84) if omitted.

map

web map item ID

geopoint, geotrace, geoshape

Map

Specifies the basemap when printing the map image.

mapScale

map scale

geopoint, geotrace, geoshape

Map

Specifies the map scale when printing the map image.

mapFilters

layer ID in web map JSON, query parameters

geopoint, geotrace, geoshape

Map

Specifies one or more filters of feature layers in a web map when printing the map image.

rotate

degrees

geopoint, geotrace, geoshape, image

Map, Image

Specifies the rotation angle of the map or image.

drawingInfo

currentLayer, feature layer URL

geopoint, geotrace, geoshape

Map

Specifies the drawing information when printing the map image, including symbol, label, and transparency.

src

image URL

-

-

Specifies the source URL of a dynamic image element.

size

width, height, max width, max height

image

Image

Specifies the size of the printed image.

round

places

decimal, geopoint, geoshape, geotrace

Number

Rounds a decimal number to specified decimal places.

useGrouping

boolean

decimal

Number

If true, returns a number with grouping separators determined by the locale; if false, no separators are used.

toFixed

places

decimal, geopoint, geoshape, geotrace

Number

Specifies a fixed number of digits after the decimal separator. It will pad zero if required to meet a fixed number of digits.

attachmentsDefExp

SQL expressions

image, audio, file

Image, Signature, Audio, File

Identifies attachments for a question or the current feature using the $attachment keyword.

Expression keywords

The following table lists all keywords that can be used in an expression:

KeywordDescription

$date

Inserts the current date and time when printing the report. By default, it outputs the current date using the current locale format.

Examples:

${$date | format:"MM/DD/YYYY"}
$($date | utcOffset:"+08:00"}
$($date | locale:"zh-cn"}

$image

Inserts an image element in the report. Use the src method to specify the image URL.

Example:

${$image | src:"https://upload.wikimedia.org/wikipedia/commons/1/13/Esri_Headquarters%2C_Building_Q.jpg"}

$map

Inserts a map element in the report without referencing a survey question.

Example:

${$map | map:"10df2279f9684e4a9f6a7f08febac2a9" | mapScale:4000000 | size:200:100}

$shape

Prints the geometry (point, polyline, or polygon) of the current feature on a map.

Examples:

${$shape}
${$shape | map:"10df2279f9684e4a9f6a7f08febac2a9" | mapScale:4000000 | size:200:100}

$attachment

Represents the first attachment, or all attachments, of the current feature.

Examples:

${$attachment | getValue:"name"}
${$attachment | getValue:"size"}
${$attachment | size:200:300}

To iterate all attachments, include start and end tags.

${#$attachment}
${$file}
${/}

$file

Represents the current file when iterating multiple files of an attachment survey question or attachments of a feature.

Examples:

${#image1}
${$file | size:460:0}
{/}

${#$attachment}
${$file | getValue:"position"}. ${$file | getValue:"name"}
${/}

$feature

Represents the current feature in an array of features.

Example:

{#repeat1}
{$feature | getValue: "position"}
{/}

$layers["<layername>"] or

$layers[<layerId>]

References any layer by name or ID in the same feature service as the survey layer.

Examples:

${$layers["cities"] | where:”1=1 !important” | stats:”count,objectid”}
${#$layers["states"]}...${/}