Data Functions

A set of convenient functions for working with and manipulating various types of data values.

Console

Console( message [,obj,text, ...objN,textN] ) -> returns: Text

Logs a message in the messages window for debugging purposes. This function can be especially useful for inspecting variable values within a custom function at runtime. Unlike other functions and the return statement, Console() doesn't actually return a value; rather, it logs messages in a separate window for inspection purposes only. The successful use of this function has no computational impact on the evaluation of the expression.

Name Type Description
message [,obj,text, ...objN,textN] * A list of variables, messages, or objects to output in the messages window.
Returns: Text
Example

Prints the value of max for each iteration of the loop within the function

// The messages window will log the following:
// 'current item is: 10, but max = 10'
// 'current item is: 0, but max = 10'
// 'current item is: 84, but max = 84'
// 'current item is: 30, but max = 84'

// The expression evaluates to 84
function findMax(yourArray) {
  var max = -Infinity;
  for (var i in yourArray) {
    max = IIf(yourArray[i] > max, yourArray[i], max);
    Console('current item is: ' + i + ', but max = ' + max);
  }
  return max;
}
var myArray = [ 10, 0, 84, 30];
findMax(myArray);


Count

Count( values ) -> returns: Number

Returns the number of items in an array or FeatureSet, or the number of characters in a string.

Name Type Description
values Array | Text | FeatureSet An array or string on which to perform the operation. In profiles that support accessing data, this can be a FeatureSet.
Returns: Number
Example

Returns 6

Count([12,21,32,44,58,63])

Returns 13

Count('Graham County')

Returns the number of features in a layer

Count($layer)

Dictionary

Dictionary( name1, value1, [...nameN, compareN]? ) -> returns: Dictionary

Returns a new dictionary based on the provided arguments. The arguments are name/value pairs. e.g. dictionary('field1',val,'field2',val2,...).

Name Type Description
name1 Text The attribute name.
value1 * The attribute value.
[...nameN, compareN] * optional Ongoing name/value pairs.
Returns: Dictionary
Example

prints 3

var d = Dictionary('field1', 1, 'field2',2)
return d.field1 + d.field2


Distinct

Distinct( values ) -> returns: Array

Since version 1.1

Returns a set of distinct, or unique, values for a given array or list of values.

Name Type Description
values Array An array or list of values on which to perform the operation.
Returns: Array
Example

Returns [1,2,3,4,5]

Distinct([1,1,2,1,1,2,2,3,4,5])

Returns ['high','medium','low',0]

Distinct('high','medium','low',0,'high','high','low')

DomainCode

DomainCode( feature, fieldName, value, subtype? ) -> returns: Text

Returns the code of an associated a domain description in a feature.

Name Type Description
feature Feature | FeatureSet The feature with a field that has a domain. In profiles that support accessing data, this can be a FeatureSet.
fieldName Text The name of the field (not the alias of the field) containing the domain.
value Text The value to be converted back into a code. This parameter is required when a FeatureSet is passed to the feature parameter. The returned code comes from the service metadata.
subtype Text optional The coded number for the subtype if the feature supports subtyping. If not provided, the current feature's subtype (if it has one), will be used.
Returns: Text
Example

prints the domain description for the field referenced.

DomainCode($feature, 'Enabled', 'True')

DomainName

DomainName( feature, fieldName, code?, subtype? ) -> returns: Text

Returns the descriptive name for a domain code in a feature.

Name Type Description
feature Feature | FeatureSet The feature with a field that has a domain. In profiles that support accessing data, this can be a FeatureSet.
fieldName Text The name of the field (not the alias of the field) containing the domain.
code Text optional The code associated with the desired descriptive name. If not provided, the field value in the feature will be returned. This parameter is required when a FeatureSet is passed to the feature parameter. The returned code comes from the service metadata.
subtype Text optional The coded number of the subtype if the feature supports subtyping. If not provided, the feature's subtype (if it has one) will be used.
Returns: Text
Example

prints the domain description for the referenced field

DomainName($feature, 'fieldName')

Feature

Feature( geometry, name1, value1, [... nameN, valueN]? ) -> returns: Feature

Creates a new feature. Alternatively, it can be called with object notation: Feature({geometry: {}, attributes: {...}}) or with two parameters: Feature(geometry, attributes);.

Name Type Description
geometry Geometry The geometry of the feature.
name1 Text The first attribute's name.
value1 Text | Date | Number | Boolean The first attribute's value.
[... nameN, valueN] * optional Ongoing name/value pairs for each attribute in the feature.
Returns: Feature
Example
Feature(pointGeometry, 'city_name', 'Spokane', 'population', 210721)
Create a feature from another feature.
var dict = { hello:10 }
var p = point({x:10, y:20, spatialReference:{wkid:102100}})
var ftr1 = Feature(p,dict)
var ftr2 = Feature(ftr1)

Create a feature from a JSON string.
var JSONString = "{'geometry':{'x':10,'y':20,'spatialReference':{'wkid':102100}},'attributes':{'hello':10}}"
var feature = Feature(JSONString)


FeatureSet

FeatureSet( definition ) -> returns: FeatureSet

Since version 1.5

Profiles: Attribute Rules | Popup | Field Calculate

Creates a new FeatureSet from JSON according to the ArcGIS REST spec. See the snippet below for an example of this.

Name Type Description
definition Text The JSON describing a set of features. The JSON must be contained in a string.
Returns: FeatureSet
Example
Create a FeatureSet from JSON.
// JSON representation of the feature used in the snippet below
// {
//   'fields': [{
//     'alias': 'RANK',
//     'name': 'RANK',
//     'type': 'esriFieldTypeInteger'
//   }, {
//     'alias': 'ELEV_m',
//     'name': 'ELEV_m',
//     'type': 'esriFieldTypeInteger'
//   }],
//   'spatialReference': { 'wkid': 4326 },
//   'geometryType': 'esriGeometryPoint',
//   'features': [{
//     'geometry': {
//       'spatialReference': { 'wkid': 4326 },
//       'x': -151.0063,
//       'y': 63.069
//     },
//     'attributes': {
//       'RANK': 1,
//       'ELEV_m': 6168
//     }
//   }]
// };
// The Dictionary representation of the FeatureSet must be a stringified object
var features = FeatureSet('{"fields":[{"alias":"RANK","name":"RANK","type":"esriFieldTypeInteger"},{"alias":"ELEV_m","name":"ELEV_m","type":"esriFieldTypeInteger"}],"spatialReference":{"wkid":4326},"geometryType":"esriGeometryPoint","features":[{"geometry":{"spatialReference":{"wkid":4326},"x":-151.0063,"y":63.069},"attributes":{"RANK":1,"ELEV_m":6168}}]}')


FeatureSetById

FeatureSetById( map, id, fieldList?, includeGeometry? ) -> returns: FeatureSet

Since version 1.5

Profiles: Attribute Rules | Popup | Field Calculate

Creates a FeatureSet from a Feature Layer based on its layer ID within a map or feature service. Limiting the number of fields in the request and excluding the geometry can improve the performance of the script.

Name Type Description
map FeatureSetCollection The map or feature service containing one or more layers from which to create a FeatureSet. Typically, this value is the $map or $datastore global.
id Text The ID of the layer within the given map.
fieldList Text[] optional The fields to include in the FeatureSet. By default, all fields are included. To request all fields in the layer, set this value to ['*']. Limiting the number of fields improves the performance of the script.
includeGeometry Boolean optional Indicates whether to include the geometry in the features. By default, this is true. For performance reasons, you should only request the geometry if necessary, such as for use in geometry functions.
Returns: FeatureSet
Example
Returns the number of features in the layer with the id DemoLayerWM_1117 in the given map.
var features = FeatureSetById($map,'DemoLayerWM_1117', ['*'], true);
Count( features );


FeatureSetByName

FeatureSetByName( map, title, fieldList?, includeGeometry? ) -> returns: FeatureSet

Since version 1.5

Profiles: Attribute Rules | Popup | Field Calculate

Creates a FeatureSet from a Feature Layer based on its name within a map or feature service. Keep in mind this name is not necessarily unique. It is therefore more appropriate to create a FeatureSet using FeatureSetById(). Limiting the number of fields in the feature set and excluding the geometry can improve the performance of the script.

Name Type Description
map FeatureSetCollection The map or feature service containing one or more layers from which to create a FeatureSet. Typically, this value is the $map or $datastore global.
title Text The title of the layer within the given map.
fieldList Text[] optional The fields to include in the FeatureSet. By default, all fields are included. To request all fields in the layer, set this value to ['*']. Limiting the number of fields improves the performance of the script.
includeGeometry Boolean optional Indicates whether to include the geometry in the features. By default, this is true. For performance reasons, you should only request the geometry if necessary, such as for use in geometry functions.
Returns: FeatureSet
Example
Returns the number of features in the layer with the title 'Bike routes' in the given map.
var features = FeatureSetByName($map,'Bike routes', ['*'], true);
Count( features );


FeatureSetByPortalItem

FeatureSetByPortalItem( itemId, layerId, fieldList?, includeGeometry? ) -> returns: FeatureSet

Since version 1.5

Profiles: Field Calculate

Creates a FeatureSet from a Feature Layer in a portal item. Limiting the number of fields in the feature set and excluding the geometry can improve the performance of the script.

Name Type Description
itemId Text The GUID of the portal item referencing a feature layer or feature service.
layerId Number The ID of the layer in the feature service.
fieldList Text[] optional The fields to include in the FeatureSet. By default, all fields are included. To request all fields in the layer, set this value to ['*']. Limiting the number of fields improves the performance of the script.
includeGeometry Boolean optional Indicates whether to include the geometry in the features. For performance reasons, you should only request the geometry if necessary, such as for use in geometry functions.
Returns: FeatureSet
Example
Returns the number of features in the layer with the title 'Bike routes' in the given map.
var features = FeatureSetByPortalItem('7b1fb95ab77f40bf8aa09c8b59045449', 0, ['Name', 'Count'], false);
Count( features );


Filter

Filter( featureSet, filter ) -> returns: FeatureSet

Since version 1.5

Profiles: Attribute Rules | Popup | Field Calculate

Filters a FeatureSet based on a SQL92 expression.

Name Type Description
featureSet FeatureSet The FeatureSet, or layer, to filter.
filter Text The SQL92 expression used to filter features in the layer. This expression can substitute an Arcade variable using the @ character. See the snippet below for an example.
Returns: FeatureSet
Example
Filter features using a SQL92 expression
// Returns all features with a Population greater than 10,000
var result = Filter($layer, 'POPULATION > 10000');

Filter features using a SQL92 expression with a variable substitute
// Returns all features with a Population greater than the dataset average
var averageValue = Average($layer, 'POPULATION')
var result = Filter($layer, 'POPULATION > @averageValue');


First

First( items ) -> returns: *

Returns the first element in an array or FeatureSet.

Name Type Description
items Array The array from which to return the first feature. In profiles that support accessing data, this can be a FeatureSet.
Returns: *
Example

prints 'orange'

First(['orange', 'purple', 'gray'])

returns the area of the first feature in the layer.

Area( First($layer) )

Guid

Guid( format? ) -> returns: Text

Since version 1.3

Returns a random GUID as a string.

Name Type Description
format Text optional An named format for the GUID. The default value is digits-hyphen-braces.

Possible Values: digits / digits-hyphen / digits-hyphen-braces / digits-hyphen-parentheses
Returns: Text
Example

Returns a value similar to {db894515-ed21-4df1-af67-36232256f59a}

Guid()

Returns a value similar to d00cf4dffb184caeb8ed105b2228c247

Guid('digits')

HasKey

HasKey( feature, key ) -> returns: Boolean

Indicates whether a dictionary or feature has the input key.

Name Type Description
feature Dictionary | Feature The dictionary or feature to check for a key or field name.
key Text The key or field name to check.
Returns: Boolean
Example

prints true

var d = Dictionary('Port Hope', 16214,  'Grafton', '<1000', 'Cobourg', 18519);
HasKey(d, 'Cobourg');


IndexOf

IndexOf( inputArray, item ) -> returns: Number

Returns the zero-based index location of the input item in an array. If item does not exist, then -1 is returned.

Name Type Description
inputArray Array The array to search.
item * The item to locate in the array.
Returns: Number
Example

prints 2

var array = [1,2,3,4];
return indexof(array, 3);


IsNan

IsNan( value ) -> returns: Boolean

Since version 1.5

Indicates whether the input value is not a number (NaN). A number is considered NaN in one of the following scenarios:

  • 0/0
  • Infinity / Infinity
  • Infinity * 0
  • Any operation in which NaN is an operand
  • Casting a non-numeric string or undefined to a number

Name Type Description
value * The value to check if it is NaN.
Returns: Boolean
Example
// Returns true
IsNan(Infinity / Infinity)

// Returns false
IsNan('4')


NextSequenceValue

NextSequenceValue( inputSequenceName ) -> returns: Number

Since version 1.4

Profiles: Attribute Rules

Returns the next sequence value from the database sequence specified. If inputSequenceName does not exist, the expression will error. This function is only valid in the calculation profile when used in attribute rules.

Name Type Description
inputSequenceName Text The name of the sequence. This must already be configured in the database.
Returns: Number
Example

Returns a number with the next sequence value

NextSequenceValue('PipeIDSeq')


Number

Number( value, pattern? ) -> returns: Number

Parses the input value to a number.

Name Type Description
value * The value to convert to a number.
pattern Text optional The format pattern string used to parse numbers formatted in a localized context from a string value to a number. The table below describes the characters that may be used in the pattern.

ValueDescription
0Mandatory digits
#Optional digits
%Divide by 100
Returns: Number
Example
Parses a number using a grouping separator appropriate for the local in which the expression is executed

returns 1365

Number('1,365', ',###')
Remove strings from number.

prints 10

Number('abc10def', 'abc##def')
Specify minimum digits past 0 as two and maximum digits past 0 as 4.

prints 10.456

Number('10.456','00.00##')
Specify minimum digits past 0 as two and maximum digits past 0 as 4. The left and right side of the function must match or NaN is returned.

prints NaN

Number('10.4','00.00##')
Indicate the size of the repeated group and the final group size of the input value.

prints 1212456

Number('12,12,456', ',##,###')
If there is a negative subpattern, it serves only to specify the negative prefix and suffix.

prints -1223345

Number('-12,23,345', ',##,###;-,##,###')
Divide by 100. Maximum of three decimal places can be input.

prints 0.9999

Number('99.99%', '#.##%')

OrderBy

OrderBy( featureSet, expression ) -> returns: FeatureSet

Since version 1.5

Profiles: Attribute Rules | Popup | Field Calculate

Orders a FeatureSet by using a SQL92 OrderBy clause.

Name Type Description
featureSet FeatureSet The FeatureSet, or layer, to order.
expression Text The SQL92 expression used to order features in the layer.
Returns: FeatureSet
Example
Order features by population where features with the highest population are listed first
OrderBy($layer, 'POPULATION DESC')

Order features by rank in ascending order
OrderBy($layer, 'Rank ASC')


Reverse

Reverse( inputArray ) -> returns: Array

Reverses the contents of the array in place.

Name Type Description
inputArray Array The array to be reversed.
Returns: Array
Example

returns ['grey', 'purple', 'orange']

Reverse(['orange', 'purple', 'grey'])

Sort

Sort( inputArray, comparator? ) -> returns: Array

Sorts an array by ASCII value. If all the items in the array are the same type, an appropriate sort function will be used. If they are different types, the items will be converted to strings. If the array contains objects, and no user defined function is provided, no sort will happen.

Name Type Description
inputArray Array The array to sort.
comparator Text optional The name of a user defined function to be used for the sort.
Returns: Array
Example

returns ['$', 1, 'A', 'a']

Sort([1, 'a', '$', 'A'])
Sort using a user defined function

returns '[{ 'AGE': 24, 'NAME': 'Emma' }, { 'AGE': 25, 'NAME': 'Sam' }, { 'AGE': 27, 'NAME': 'Bob' } ]'

var peopleArray = [{ 'NAME': 'Sam', 'AGE': 25 }, {'NAME': 'Bob', 'AGE': 27 },{ 'NAME': 'Emma', 'AGE': 24 }];
function compareAge(a,b){
  if (a['AGE']<b['AGE'])
    return -1;
  if (a['AGE']>b['AGE'])
    return 1;
  return 0;
}
return Sort(peopleArray, compareAge);


Text

Text( value, format? ) -> returns: Text

Converts its argument into a string and optionally formats it. Returns null if it fails.

Name Type Description
value * A value to be converted to a string (e.g. date, number or other type).
format Text optional Formatting string for dates or numbers. See the list of possible values below.

ValueDescription
0Digit
#Digit, omitting leading/trailing zeros
DDay of the month, not padded (1 - 31).
DDDay of the month, padded (01 - 31).
DDDOrdinal day of the year (1 - 365).
dDay of the week (1 - 7)
dddAbbreviated day of the week (e.g. Mon)
ddddFull day of the week (e.g. Monday).
MMonth number (1 - 12)
MMMonth number, padded (01 - 12).
MMMAbbreviated month name (e.g. Jan).
MMMMFull month name (e.g. January)
mMinutes, not padded (0 - 59).
mmMinutes, padded (00 - 59).
YFull year
YYTwo-digit year
hCivilian hours, not padded (0 - 12)
hhCivilian hours, padded (00 - 12)
HMilitary hours, not padded (0 - 24)
HHMilitary hours, padded (00 - 24)
sSeconds, not padded (0 - 59)
ssSeconds, padded (00 - 59)
Returns: Text
Example
Pad the number to the left of the decimal

prints '0123'

Text(123, '0000')
Restrict the number to the left of the decimal

prints '23'

Text(123, '00')
Group the number by thousands

prints '1,234'

Text(1234, '#,###')
Round the number to two decimal places

prints '12,345,678.12'

Text(12345678.123, '#,###.00')
Format number as currency

prints '$1,234.55'

Text(1234.55, '$#,###.00')
Round the number to two decimal places

prints '1.24'

Text(1.236, '#.00')
Maintain significant digits and group by thousands

prints '1,234.568'

Text(1234.5678, '#,##0.00#')
Format the number and format positive/negative - if there is a negative subpattern, it serves only to specify the negative prefix and suffix

prints 'Basement 2'

Text(-2, 'Floor #;Basement #')

prints 'Floor 2'

Text(2, 'Floor #;Basement #')
Multiply by 100 and format as percentage

prints '30%'

Text(0.3, '#%')
Format date and time

prints the date at the moment. eg 'Tuesday, October 25, 2016 @ 08:43:11'

Text(Now(), 'dddd, MMMM D, yyyy @ h:m:s')

Top

Top( items, numElements ) -> returns: Array / FeatureSet

Since version 1.3

Truncates the input array or FeatureSet and returns the first given number of elements.

Name Type Description
items Array | FeatureSet The array to truncate. In profiles that support accessing data, this can be a FeatureSet.
numElements Number The number of elements to return from the beginning of the array or FeatureSet.
Returns: Array | FeatureSet
Example
returns [ 43,32,19 ]
Top([ 43,32,19,0,3,55 ], 3)
Returns the top 5 features with the highest population
Top( OrderBy($layer, 'POPULATION DESC'), 5 )

TypeOf

TypeOf( value ) -> returns: Text

Returns the type of the input value. Will return one of the following types: Array, Date, Text, Boolean, Number, Dictionary, Feature, Point, Polygon, Polyline, Multipoint, Extent, Function, Unrecognized Type.

Name Type Description
value * The input value, variable, or feature attribute.
Returns: Text
Example

prints 'Boolean'

TypeOf(true)

prints 'Date'

TypeOf(Now())


Feedback on this topic?