Data Functions
A set of convenient functions for working with and manipulating various types of data values.
All
All(inputArray, testFunction) -> Boolean
Indicates whether all of the elements in a given array pass a test from the provided function. Returns true
if the function returns true
for all items in the input array.
Parameters
-
testFunction: Function - The function used to test each element in the array
testFunction(value: Any) -> Boolean
. The function must return a truthy value if the element passes the test. The function can be a user-defined function or a core Arcade function defined with the following parameter:- value: Any - Represents the value of an element in the array.
Return value: Boolean
true
if the test function returns a truthy value for all the elements.
Examples
Returns false
because some of the elements in the input array do not pass the isEven
test
// isEven is used to test if each element in the array is even
// it returns true if the element is divisible by two, false if is not
function isEven(value) { return value % 2 == 0 }
// The isEven function will execute for each element in the array,
// returning the following values: false, true, false, true, false
// Since some of the values in the array did not pass the test
// (return true), the return value will be false
Any([1,2,3,4,5], isEven)
Uses the existing isEmpty
Arcade function as the testFunction
. This is valid because isEmpty
takes a single parameter and returns a boolean value. This expression returns true
if all of the fields are empty.
var myArray = [ $feature.field1, $feature.field2, $feature.field3, $feature.field4];
All(myArray, isEmpty)
Any
Any(inputArray, testFunction) -> Boolean
Tests whether any of the elements in a given array pass a test from the provided function. Returns true
if the function returns true
for at least one item in the input array.
Parameters
-
testFunction: Function - The function used to test each element in the array
testFunction(value: Any) -> Boolean
. The The function must return a truthy value if the element passes the test. The function can be a user-defined function or a core Arcade function defined with the following parameter:- value: Any - Represents the value of an element in the array.
Return value: Boolean
true
if the test function returns a truthy value for any of the elements.
Examples
Returns true
because at least one element in the input array passes the isEven
test.
// isEven is used to test if each element in the array is even
// it returns true if the element is divisible by two, false if is not
function isEven(value) { return value % 2 == 0 }
// The isEven function will execute for each element in the array,
// returning the following values: false, true, false, true, false
// Since at least one value in the array passed the test
// (return true), the return value will be true
Any([1,2,3,4,5], isEven)
Uses the existing isEmpty
Arcade function as the testFunction
. This is valid because isEmpty
takes a single parameter and returns a boolean value. This expression returns true
if any of the fields are empty.
var myArray = [ $feature.field1, $feature.field2, $feature.field3, $feature.field4];
Any(myArray, isEmpty)
Array
Array(value, defaultValue?) -> Array<Any>
Returns a new array of a given length.
Parameters
- value: Number - The desired length for the new array.
- defaultValue (Optional): Any - The value for each element in the array. If no value is specified, the default will be
null
.
Examples
Returns [null, null, null, null, null]
.
Array(5)
Returns [1,1,1]
.
Array(3, 1)
Attachments
Attachments(inputFeature, options?) -> Array<Attachment>
Profiles: Field Calculation | Form Calculation | Attribute Rules | Popups | Tasks
Returns a list of attachments associated with the input feature. Each result includes the name of the attachment, the content type, id, and size in bytes.
Parameters
-
inputFeature: Feature - Attachments associated with this feature will be fetched from the service.
-
options (Optional): Dictionary - Settings for the request. Dictionary properties:
- types: Array<Text> - An array of strings representing the file types to fetch. The following are supported values:
bmp, ecw, emf, eps, ps, gif, img, jp2, jpc, j2k, jpf, jpg, jpeg, jpe, png, psd, raw, sid, tif, tiff, wmf, wps, avi, mpg, mpe, mpeg, mov, wmv, aif, mid, rmi, mp2, mp3, mp4, pma, mpv2, qt, ra, ram, wav, wma, doc, docx, dot, xls, xlsx, xlt, pdf, ppt, pptx, txt, zip, 7z, gz, gtar, tar, tgz, vrml, gml, json, xml, mdb, geodatabase
- minsize: Number - The minimum file size of the attachment in bytes.
- maxsize: Number - The maximum file size of the attachment in bytes.
- metadata (Optional): Boolean - Indicates whether to include attachment metadata in the function return. Only Exif metadata for images is currently supported.
- types: Array<Text> - An array of strings representing the file types to fetch. The following are supported values:
Return value: Array<Attachment>
Example
Returns the number of attachments associated with the feature
// Returns the number of attachments associated with the feature
Count(Attachments($feature))
Back
Back(inputArray) -> Any
Returns the last element of an array. If the array is empty, then Back(inputArray)
will cause the script evaluation to fail.
Parameter
Return value: Any
Example
Returns 'gray'
.
var colors = ['orange', 'purple', 'gray']
Back(colors)
Boolean
Boolean(value) -> Boolean
Attempts to convert the given non-boolean value to a boolean value. For example a string 'true' would become true
.
Parameter
Return value: Boolean
Examples
// returns `true`
Boolean('true')
// returns `false`. A value of 1 would return `true`
Boolean(0)
// returns `false`
Boolean('hello')
Console
Console(value, [value2, ..., valueN]?) -> Null
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.
Parameters
- value: Any - A value to output in the messages window.
- [value2, ..., valueN] (Optional): Any - A list of variables, text, number, or dictionary to output in the messages window.
Return value: Null
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
This function has 2 signatures:
Count(value) -> Number
Returns the number of items in an array or the number of characters in a text.
Parameter
Return value: Number
Examples
Returns 6
Count([12,21,32,44,58,63])
Returns 13
Count('Graham County')
Count(features) -> Number
Returns the number of features in a layer.
Parameter
- features: FeatureSet - A FeatureSet from which to count the number of features
Return value: Number
Example
Returns the number of features in a layer
Count($layer)
Dictionary
This function has 2 signatures:
- Dictionary(name1, value1, [name2, value2, ..., nameN, valueN]?) -> Dictionary
- Dictionary(jsonText) -> Dictionary
Dictionary(name1, value1, [name2, value2, ..., nameN, valueN]?) -> Dictionary
Returns a new dictionary based on the provided arguments. The arguments are name/value pairs. e.g. dictionary('field1',val,'field2',val2,...).
Parameters
- name1: Text - The attribute name.
- value1: Any - The attribute value to pair to
name1
. - [name2, value2, ..., nameN, valueN] (Optional): Any - Ongoing name/value pairs.
Return value: Dictionary
Example
prints 3
var d = Dictionary('field1', 1, 'field2', 2)
return d.field1 + d.field2
Dictionary(jsonText) -> Dictionary
Returns a new dictionary from stringified JSON.
Parameter
- jsonText: Text - The stringified JSON to convert to an Arcade dictionary.
Return value: Dictionary
Example
Creates a dictionary from stringified JSON
var extraInfo = '{"id": 1, "population": 200, "city": "Spencer, ID"}'
var spencerIDdata = Dictionary(extraInfo)
spencerIDdata.population // Returns 200
Distinct
This function has 2 signatures:
Distinct(values) -> Array<Any>
Returns a set of distinct, or unique, values for a given array or list of values.
Parameter
Examples
Distinct([1,1,2,1,1,2,2,3,4,5])
// Returns [1,2,3,4,5]
Distinct('high','medium','low',0,'high','high','low')
// Returns ['high','medium','low',0]
Distinct(features, fields) -> FeatureSet
Profiles: Attribute Rules | Dashboard Data | Field Calculation | Form Calculation | Popups | Tasks
Returns a set of distinct, or unique, values from a FeatureSet.
Parameters
-
features: FeatureSet - A FeatureSet from which to return distinct values.
-
fields: Text | Dictionary | Array<Text> | Array<Dictionary> - The field(s) and/or expression(s) from which to determine unique values. This parameter can be an array of field names, an array of expressions, or a dictionary or array of dictionary that specify output column names where unique values will be stored. If a dictionary is specified, the folowing specification must be used:
Return value: FeatureSet
Examples
Returns a FeatureSet with a 'Status' column. Each row of the FeatureSet contains a unique status value
Distinct($layer, 'Status')
Returns a FeatureSet with a 'Status' and a 'Type' column. Each row of the FeatureSet contains a unique combination of 'Status' and 'Type' values
Distinct($layer, ['Status', 'Type'])
Returns FeatureSet with a Density column with rows that may contain values of Low, High, or N/A
Distinct($layer, {
name: "Density",
expression: "CASE WHEN PopDensity < 100 THEN 'Low' WHEN PopDensity >= 100 THEN 'High' ELSE 'N/A' END"
})
Returns FeatureSet with a Score and a Type column
Distinct($layer, [{
name: 'Score',
expression: 'POPULATION_DENSITY * 0.65 + Status_Code * 0.35'
}, {
name: 'Type',
expression: 'Category'
}])
Domain
This function has 2 signatures:
Domain(inputFeature, fieldName) -> Dictionary
Returns the domain assigned to the given field of the provided feature
. If the feature
belongs to a class with a subtype, this returns the domain assigned to the subtype.
Parameters
- inputFeature: Feature - The Feature with a field that has a domain.
- fieldName: Text - The name of the field (not the alias of the field) assigned the domain.
Return value: Dictionary
Returns a dictionary described by the properties below.
- type: Text - The type of domain - either
codedValue
orrange
. - name: Text - The domain name.
- dataType: Text - The data type of the domain field. It can be one of the following values:
esriFieldTypeSmallInteger
,esriFieldTypeInteger
,esriFieldTypeSingle
,esriFieldTypeDouble
,esriFieldTypeString
,esriFieldTypeDate
,esriFieldTypeOID
,esriFieldTypeGeometry
,esriFieldTypeBlob
,esriFieldTypeRaster
,esriFieldTypeGUID
,esriFieldTypeGlobalID
,esriFieldTypeXML
. - codedValues: Array<Dictionary> - Only applicable to
codedValue
domains. An array of dictionaries describing the valid values for the field. Each dictionary has acode
property, which contains the actual field value, and aname
property containing a user-friendly description of the value (e.g.{ code: 1, name: "pavement" }
). - min: Number - Only applicable to
range
domains. The minimum value of the domain. - max: Number - Only applicable to
range
domains. The maximum value of the domain.
Example
The domain assigned to the feature's subtype
var d = Domain($feature, "poleType")
// the poleType field has a coded value domain called poleTypes
// the value of d will be
// {
// type: "codedValue" ,
// name: "poleTypes",
// dataType: "number",
// codedValues: [
// { name: "Unknown", code: 0 },
// { name: "Wood", code: 1 },
// { name: "Steel", code: 2 }
// ]
// }
Domain(features, fieldName, subtype?) -> Dictionary
Profiles: Attribute Rules | Dashboard Data | Popups | Field Calculation | Form Calculation | Tasks
Returns the domain assigned to the given field of the provided featureSet
. If the featureSet
belongs to a class with a subtype, this returns the domain assigned to the subtype.
Parameters
- features: FeatureSet - The FeatureSet whose features contain a field that has a domain.
- fieldName: Text - The name of the field (not the alias of the field) containing the domain.
- subtype (Optional): Text | Number - The coded value for the subtype if the feature supports subtypes.
Return value: Dictionary
Returns a dictionary described by the properties below.
- type: Text - The type of domain - either
codedValue
orrange
. - name: Text - The domain name.
- dataType: Text - The data type of the domain field. It can be one of the following values:
esriFieldTypeSmallInteger
,esriFieldTypeInteger
,esriFieldTypeSingle
,esriFieldTypeDouble
,esriFieldTypeString
,esriFieldTypeDate
,esriFieldTypeOID
,esriFieldTypeGeometry
,esriFieldTypeBlob
,esriFieldTypeRaster
,esriFieldTypeGUID
,esriFieldTypeGlobalID
,esriFieldTypeXML
. - min: Number - Only applicable to
range
domains. The minimum value of the domain. - max: Number - Only applicable to
range
domains. The maximum value of the domain. - codedValues: Array<Dictionary> - Only applicable to
codedValue
domains. An array of dictionaries describing the valid values for the field. Each dictionary has acode
property, which contains the actual field value, and aname
property containing a user-friendly description of the value (e.g.{ code: 1, name: "pavement" }
).
Example
The domain assigned to the feature's subtype
var fsPole = FeatureSetByName($layer, "Pole", 1);
var d = Domain(fsPole, "poleType")
// the poleType field has a coded value domain called poleTypes
// the value of d will be
// {
// type: "codedValue" ,
// name: "poleTypesThreePhase",
// dataType: "number",
// codedValues: [
// { name: "Unknown", code: 0 },
// { name: "Wood", code: 1 },
// { name: "Steel", code: 2 }
// { name: "Reinforced Steel", code: 3 }
// ]
// }
DomainCode
This function has 2 signatures:
- DomainCode(inputFeature, fieldName, value?, subtype?) -> Text
- DomainCode(features, fieldName, value, subtype?) -> Text
DomainCode(inputFeature, fieldName, value?, subtype?) -> Text
Returns the code of an associated domain description in a feature.
Parameters
- inputFeature: Feature - The feature with a field that has a domain.
- fieldName: Text - The name of the field (not the alias of the field) containing the domain.
- value (Optional): Text - The value to be converted back into a code.
- subtype (Optional): Text - 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.
Return value: Text
Example
prints the domain description for the field referenced.
DomainCode($feature, 'Enabled', 'True')
DomainCode(features, fieldName, value, subtype?) -> Text
Returns the code of an associated domain description in a feature set.
Parameters
- features: FeatureSet - The feature set with a field that has a domain.
- 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. The returned code comes from the service metadata.
- subtype (Optional): Text - The coded number for the subtype if the feature set supports subtyping.
Return value: Text
Example
prints the domain description for the field referenced.
DomainCode($layer, 'Enabled', 'True', subtype)
DomainName
This function has 2 signatures:
- DomainName(inputFeature, fieldName, code?, subtype?) -> Text
- DomainName(features, fieldName, code?, subtype?) -> Text
DomainName(inputFeature, fieldName, code?, subtype?) -> Text
Returns the descriptive name for a domain code in a feature.
Parameters
- inputFeature: Feature - The feature with a field that has a domain.
- fieldName: Text - The name of the field (not the alias of the field) containing the domain.
- code (Optional): Text - The code associated with the desired descriptive name. If not provided, the field value in the feature will be returned.
- subtype (Optional): Text - 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.
Return value: Text
Example
prints the domain description for the referenced field
DomainName($feature, 'fieldName')
DomainName(features, fieldName, code?, subtype?) -> Text
Returns the descriptive name for a domain code in a feature.
Parameters
- features: FeatureSet - A FeatureSet with a field that has a domain.
- fieldName: Text - The name of the field (not the alias of the field) containing the domain.
- code (Optional): Text - The code associated with the desired descriptive name. The returned code comes from the service metadata.
- subtype (Optional): Text - The coded number of the subtype if the FeatureSet supports subtyping.
Return value: Text
Example
prints the domain description for the referenced field
DomainName($layer, 'fieldName')
Erase
Erase(inputArray, index) -> Null
Removes a value from an array at a given index. Existing elements positioned at or above the given index will shift down one index value. The array decreases in size by one.
Parameters
- inputArray: Array<Any> - The array to remove the value from.
- index: Number - The index of the value to remove from the array. If a negative index is provided, it will be used as an offset from the end of the array.
Return value: Null
Examples
var colors = ['orange', 'purple', 'gray']
Erase(colors, 1)
// colors = ['orange','gray']
var colors = ['orange', 'purple', 'gray']
Erase(colors, -1)
// colors = ['orange','purple']
Expects
This function has 2 signatures:
- Expects(inputFeature, field1, [field2, ..., fieldN]?) -> Null
- Expects(features, field1, [field2, ..., fieldN]?) -> Null
Expects(inputFeature, field1, [field2, ..., fieldN]?) -> Null
Requests additional attributes for the given feature. In some profiles, such as Visualization and Labeling, apps only request the data attributes required for rendering each feature or label. Some expressions dynamically reference field names with variables rather than string literals. This makes it hard for rendering and labeling engines to detect fields required for rendering. This function allows you to explicitly indicate required fields as a list. You can also request all or a subset of fields using a wildcard. Because expressions execute on a per feature basis, the wildcard should be used with caution, especially in layers containing many features. Requesting too much data can result in very poor app performance.
Parameters
- inputFeature: Feature - The feature to which the requested fields will be attached.
- field1: Text - A field name to request for the given feature. List only fields required for use in the expression. If necessary, you can request all fields using the wildcard
*
character. However, this should be avoided to prevent loading an unnecessary amount of data that can negatively impact app performance. - [field2, ..., fieldN] (Optional): Text - An ongoing list of field names to request for the given feature. List only fields required for use in the expression.
Return value: Null
Examples
Requests fields not easily detected by the renderer
// Request multiple years of population data if the
// fields cannot be easily detected by the renderer or labels
Expects($feature, 'POP_2020', 'POP_2010')
var thisYear = 2020;
var lastDecade = thisYear - 10;
return $feature['POP_'+thisYear] - $feature['POP_'+lastDecade]
Requests all data matching a pattern in the field name
// Request all the data beginning with 'POP'. This is
// necessary because the renderer can't easily detect
// the required fields based on this expression
Expects($feature, 'POP*')
var startYear = 1880;
var endYear = 2020;
var changes = [];
for(var y=startYear; y<endYear; y+=10){
var startPop = $feature['POP_' + y];
var endPop = $feature['POP_' + (y+10)];
var change = endPop - startPop;
Push(changes, change);
}
Max(changes);
Requests all data for the feature
// Request all fields because the required fields may
// be based on unknown information like a relative date
Expects($feature, '*')
var casesToday = $feature[ 'CASES_' + Text(d, 'MM_DD_Y') ];
var casesYesterday = $feature[ 'CASES_' + Text(DateAdd( Today(), -1, 'days', 'MM_DD_Y') ];
// Change in cases from yesterday
return casesToday - casesYesterday;
Expects(features, field1, [field2, ..., fieldN]?) -> Null
Requests additional attributes for the given FeatureSet.
Parameters
- features: FeatureSet - The feature set to which the requested fields will be attached.
- field1: Text - A field name to request for the given feature. List only fields required for use in the expression. If necessary, you can request all fields using the wildcard
*
character. However, this should be avoided to prevent loading an unnecessary amount of data that can negatively impact app performance. - [field2, ..., fieldN] (Optional): Text - An ongoing list of field names to request for the given feature. List only fields required for use in the expression.
Return value: Null
Example
Requests the POPULATION field for the features in the cluster
// If the layer is clustered based on count,
// only the OBJECTID field is requested by default.
// To display the sum of the POPULATION field
// for all features in the cluster, we must
// explicitly request the POPULATION data.
Expects($aggregatedFeatures, 'POPULATION')
Text(Sum($aggregatedFeatures, 'POPULATION'), '#,###')
Feature
Feature(featureGeometry, attribute1, value1, [attribute2, value2, ..., attributeN, valueN]?) -> Feature
Creates a new feature. Alternatively, it can be called with object notation: Feature({geometry: {}, attributes: {...}})
or with two parameters: Feature(inputGeometry, attributes);
.
Parameters
- featureGeometry: Geometry - The geometry of the feature.
- attribute1: Text - The first attribute's name.
- value1: Text | Date | Number | Boolean - The first attribute's value.
- [attribute2, value2, ..., attributeN, valueN] (Optional): Any - Ongoing name/value pairs for each attribute in the feature.
Return value: Feature
Examples
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}}"
Feature(JSONString)
FeatureSet
FeatureSet(definition) -> FeatureSet
Profiles: Attribute Rules | Dashboard Data | Popups | Field Calculation | Form Calculation | Tasks
Creates a new FeatureSet from JSON according to the ArcGIS REST spec. See the snippet below for an example of this.
Parameter
- definition: Text - The JSON describing a set of features. The JSON must be contained in a text value.
Return value: 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}}]}')
FeatureSetByAssociation
FeatureSetByAssociation(inputFeature, associationType, terminalName?) -> FeatureSet
Profiles: Attribute Rules | Dashboard Data | Popups | Tasks
Returns all the features associated with the input feature as a FeatureSet. This is specific to Utility Network workflows.
Parameters
- inputFeature: Feature - The feature from which to query for all associated features. This feature must be coming from a feature service; feature collections are not supported.
- associationType: Text - The type of association with the feature to be returned.
Possible Values:connected
|container
|content
|structure
|attached
Possible Values added at version 1.10:junctionEdge
|midspan
- terminalName (Optional): Text - Only applicable to
connected
association types.
Return value: FeatureSet
Returns a FeatureSet containing features with the field specification described in the table below.
- className: Text - The class name based on the value of
TONETWORKSOURCEID
orFROMNETWORKSOURCEID
. - globalId: Text - The Global ID of the feature in the other table (i.e. either the value of
TOGLOBALID
orFROMGLOBALID
). - isContentVisible: Number - Can either be a value of
1
(visible) or0
(not visible). This value represents the visibility of the associated content and is only applicable for containment associations. - objectId: Text - The ObjectID of the row in the association table.
- percentAlong: Number - Applies to
midspan
association types. Returns a floating point number from 0-1 indicating the location (as a ratio) of the junction along the edge. - side: Text - Applies to
junctionEdge
association types. Indicates which side the junction is on.
Possible values: from
or to
Examples
Returns all assets that have connectivity associations with the low side terminal of the transformer.
FeatureSetByAssociation($feature, 'connected', 'Low');
Returns the number of electric devices associated with the feature
var allContent = FeatureSetByAssociation ($feature, "content");
var devicesRows = Filter(allContent, "className = 'Electric Device'");
var devicesCount = Count(devicesRows);
return devicesCount;
FeatureSetById
FeatureSetById(featureSetCollection, id, fields?, includeGeometry?) -> FeatureSet
Profiles: Attribute Rules | Dashboard Data | Popups | Field Calculation | Form Calculation | Tasks
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.
Parameters
- featureSetCollection: 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
. This layer must be created from a feature service; feature collections are not supported. Please note that this value must be a string literal. - fields (Optional): Array<Text> - 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 (Optional): Boolean - 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.
Return value: 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(featureSetCollection, title, fields?, includeGeometry?) -> FeatureSet
Profiles: Attribute Rules | Dashboard Data | Popups | Field Calculation | Form Calculation | Tasks
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 FeatureSet and excluding the geometry can improve the performance of the script.
Parameters
- featureSetCollection: 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
. This layer must be created from a feature service; feature collections are not supported. Please note that this value must be a string literal. - fields (Optional): Array<Text> - 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 (Optional): Boolean - 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.
Return value: 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(portalObject, itemId, layerId, fields?, includeGeometry?) -> FeatureSet
Profiles: Dashboard Data | Field Calculation | Form Calculation | Popups | Tasks
Creates a FeatureSet from a Feature Layer in a portal item from a given Portal. Limiting the number of fields in the FeatureSet and excluding the geometry can improve the performance of the script.
Parameters
- portalObject: Portal - The Portal from which to query features from a given portal item ID.
- itemId: Text - The GUID of the portal item referencing a feature layer or feature service. Please note that this value must be a string literal.
- layerId: Number - The ID of the layer in the feature service. This layer must be created from a feature service; feature collections are not supported.
- fields (Optional): Array<Text> - 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 (Optional): Boolean - 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.
Return value: FeatureSet
Example
Returns the number of features in the layer from a different portal than the feature in the map.
var features = FeatureSetByPortalItem(
Portal('https://www.arcgis.com'),
'7b1fb95ab77f40bf8aa09c8b59045449',
0,
['Name', 'Count'],
false
);
Count(features);
FeatureSetByRelationshipName
FeatureSetByRelationshipName(inputFeature, relationshipName, fieldNames?, includeGeometry?) -> FeatureSet
Profiles: Attribute Rules | Dashboard Data | Field Calculation | Form Calculation | Popups | Tasks
Returns the related records for a given feature as a FeatureSet.
Parameters
- inputFeature: Feature - The feature from which to fetch related records. This feature must be coming from a feature service; feature collections are not supported.
- relationshipName: Text - The name of the relationship according to the feature service associated with the given feature.
- fieldNames (Optional): Array<Text> - The fields to return in the FeatureSet. This list includes fields from both the relationship table and the input Feature.
- includeGeometry (Optional): Boolean - Indicates whether to return the geometry for the resulting features.
Return value: FeatureSet
Example
Returns the sum of several fields across all related records
var results = FeatureSetByRelationshipName($feature, 'Election_Results', ['*'], false)
Sum(results, 'democrat + republican + other')
Filter
This function has 2 signatures:
Filter(features, sqlExpression) -> FeatureSet
Profiles: Attribute Rules | Dashboard Data | Popups | Field Calculation | Form Calculation | Tasks
Creates a new FeatureSet with all the features that pass the SQL92 expression filter.
Parameters
- features: FeatureSet - The FeatureSet, or layer, to filter.
- sqlExpression: 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.
Return value: FeatureSet
Examples
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');
Filter(inputArray, filterFunction) -> Array<Any>
Creates a new array with the elements filtered from the input array that pass a test from the provided function.
Parameters
-
filterFunction: Function - The function used to filter elements in the array
filterFunction(value: Any) -> Boolean
. The The function must return a truthy value if the element passes the test. This function can be a user-defined function or a core Arcade function defined with the following parameter:- value: Any - Represents the value of an element in the array.
Return value: Array<Any>
Returns an array with the elements that passe the test function.
Examples
Returns a new array comprised of elements that passed the isEven
filter.
function isEven(i) { return i % 2 == 0 }
Filter([1,2,3,4,5], isEven) // Returns [2,4]
// Since 2 and 4 are even, they are the only values
// included in the output array.
Uses the existing isEmpty
Arcade function in the filterFunction
. Returns a new array of fields that are not empty.
var myArray = [ $feature.field1, $feature.field2, $feature.field3, $feature.field4];
function isNotEmpty(value){
return !isEmpty(value);
}
Filter(myArray, isNotEmpty)
// Returns only values that are defined,
// excluding empty values from the result
First
This function has 2 signatures:
First(inputArray) -> Any
Returns the first element in an array. Returns null
if the array is empty.
Parameter
Return value: Any
Example
prints 'orange'
First(['orange', 'purple', 'gray'])
First(features) -> Feature
Returns the first feature in a FeatureSet. Returns null
if the FeatureSet is empty.
Parameter
- features: FeatureSet - The FeatureSet from which to return the first feature.
Return value: Feature
Example
returns the area of the first feature in the layer.
Area( First($layer) )
FromJSON
FromJSON(jsonText) -> Dictionary | Array<Any> | Text | Boolean | Number
Converts stringified (serialized) JSON objects into their equivalent Arcade data types.
Parameter
- jsonText: Text - The stringified JSON to deserialize to an Arcade data type.
Return value: Dictionary | Array<Any> | Text | Boolean | Number
Examples
Converts text to a boolean
FromJSON("true")
// Returns true
Converts text to a number
fromJSON("731.1")
// returns 731.1
Converts text to a dictionary
var d = fromJSON('{"kids": 3, "adults": 4 }')
d.kids + d.adults
// returns 7
Converts text to an array
fromJSON('["one", 2, "three", false]')
// returns [ "one", 2, "three", false ]
Converts text to null
fromJSON("null")
// returns null
GdbVersion
This function has 2 signatures:
GdbVersion(inputFeature) -> Text
Returns the name of the current geodatabase version for branch or versioned data. When the data is not in a multi-user geodatabase, an empty string will be returned. See Overview of Versioning for more information.
Parameter
- inputFeature: Feature - A Feature from which to return the current geodatabase version of the associated layer.
Return value: Text
Example
Returns the geodatabase version of the given feature
GdbVersion($feature)
GdbVersion(features) -> Text
Returns the name of the current geodatabase version for branch or versioned data. When the data is not in a multi-user geodatabase, an empty string will be returned. See Overview of Versioning for more information.
Parameter
- features: FeatureSet - A FeatureSet from which to return the current geodatabase version.
Return value: Text
Example
Returns the geodatabase version of the given FeatureSet
GdbVersion($layer)
GetFeatureSet
GetFeatureSet(inputFeature, source?) -> FeatureSet
Profiles: Attribute Rules | Dashboard Data | Popups | Field Calculation | Form Calculation | Tasks
Gets the FeatureSet in which the input feature belongs. The returned FeatureSet represents all features from the input feature's parent/root layer or table.
Parameters
- inputFeature: Feature - The feature belonging to a parent or root FeatureSet.
- source (Optional): Text - Indicates the source FeatureSet to return.
Possible Values:
datasource
: (default) Returns all the features from the input feature's data source without any filters or definition expressions as a FeatureSet.root
: Returns the initial FeatureSet to which the input feature belongs. This may be a filtered subset of all the features in the data source.parent
: Returns the parent FeatureSet of the input feature. This can be a smaller set of features than the original data source or root FeatureSet.
Return value: FeatureSet
Examples
Returns a FeatureSet representing all the features in the data source.
// The data source for the 'Bike routes' layer has 2,000 features.
// The map sets a definition expression on the 'Bike routes' layer and filters it to 100 features.
var fs1 = FeatureSetByName($map, 'Bike routes', ['*'], true);
var fs2 = top(fs1, 10)
var f = First(fs2)
GetFeatureSet(f)
// returns a FeatureSet representing the data source with 2,000 features
Returns the root FeatureSet of the feature.
// The data source for the 'Bike routes' layer has 2,000 features.
// The map sets a definition expression on the 'Bike routes' layer and filters it to 100 features.
var fs1 = FeatureSetByName($map, 'Bike routes', ['*'], true);
var fs2 = top(fs1, 10)
var f = First(fs2)
GetFeatureSet(f, 'root')
// returns the root FeatureSet representing 100 features
Returns the parent FeatureSet of the feature.
// The data source for the 'Bike routes' layer has 2,000 features.
// The map sets a definition expression on the 'Bike routes' layer and filters it to 100 features.
var fs1 = FeatureSetByName($map, 'Bike routes', ['*'], true);
var fs2 = top(fs1, 10)
var f = First(fs2)
GetFeatureSet(f, 'parent')
// returns the parent FeatureSet representing 10 features
Returns the number of features in the data source table within 1 mile of the feature.
var fullFeatureSet = GetFeatureSet($feature);
var featuresOneMile = Intersects(fullFeatureSet, BufferGeodetic($feature, 1, 'miles'))
Count(featuresOneMile)
GetFeatureSetInfo
GetFeatureSetInfo(inputFeatureSet) -> Dictionary
Profiles: Attribute Rules | Dashboard Data | Popups | Field Calculation | Form Calculation | Tasks
Returns metadata for the original source database and service (if applicable) of a FeatureSet.
Parameter
- inputFeatureSet: FeatureSet - The FeatureSet from which to fetch metadata.
Return value: Dictionary
Returns a dictionary described by the properties below.
- layerId: Number - The layerId of the feature service. Only applicable to FeatureSets created from feature services. This value will be
null
for sde/filegdb/mobile workspaces. - layerName: Text - The layer name of the feature service. Only applicable to FeatureSets created from feature services. This value will be
null
for sde/filegdb/mobile workspaces. - itemId: Text - The portal item ID of the feature service. Only applicable to FeatureSets created from feature services that have an associated portal item. This value will be
null
for sde/filegdb/mobile workspaces. - serviceLayerUrl: Text - The url of the feature service layer. Only applicable to FeatureSets created from feature services. This value will be
null
for sde/filegdb/mobile workspaces. - webMapLayerId: Text - The layerId of the associated layer within the context of a web map. Only applicable to FeatureSets created from feature service layers that are contained within a web map. This value will be
null
for sde/filegdb/mobile workspaces. - webMapLayerTitle: Text - The title of the associated layer within the context of a web map. Only applicable to FeatureSets created from feature service layers that are contained within a web map. This value will be
null
for sde/filegdb/mobile workspaces. - className: Text - The name of the underlying feature class. Only applicable to FeatureSets created from feature classes in filegdb/mobile workspaces.
- objectClassId: Number - The objectClassId. Only applicable to FeatureSets created from feature classes in filegdb workspaces.
Examples
Metadata returned from a FeatureSet connected to an underlying feature service
// $layer originates from a feature service layer in a web map
GetFeatureSetInfo($layer);
// returns the following:
{
"layerId": 7,
"layerName": "My Table",
"itemId": "dda795cf2af44d2bb7af2827963b76e8",
"serviceLayerUrl": "https://utilitynetwork.esri.com/server/rest/services/ClassicNapervilleElectric_Postgres/FeatureServer/100",
"webMapLayerId": 1,
"webMapLayerTitle": "MyTable1",
"className": null,
"objectClassId": null
}
Metadata returned from a FeatureSet originating from a filegdb or mobilegdb
// $featureset originates from a feature class in a filegdb or mobilegdb
GetFeatureSetInfo($featureset);
// returns the following:
{
"layerId": null,
"layerName": null,
"itemId": null,
"serviceLayerUrl": null,
"webMapLayerId": null,
"webMapLayerTitle": null,
"className": "myTable",
"objectClassId": 7
}
Metadata returned from a FeatureSet connected to an sde workspace (client server direct connection)
// Client server direct connection (sqlserver/oracle/etc.)
GetFeatureSetInfo($featureset);
// returns the following:
{
"layerId": null,
"layerName": null,
"itemId": null,
"serviceLayerUrl": null,
"webMapLayerId": null,
"webMapLayerTitle": null,
"className": "owner.myTable",
"objectClassId": 7
}
GetUser
This function has 4 signatures:
- GetUser(portalObject, username?) -> Dictionary
- GetUser(features, username?) -> Dictionary
- GetUser(portalObject, extensions?) -> Dictionary
- GetUser(features, extensions?) -> Dictionary
GetUser(portalObject, username?) -> Dictionary
Profiles: Attribute Rules | Dashboard Data | Popups | Field Calculation | Form Calculation | Tasks
Returns the current user from the workspace. For data from a service, either the Portal user or Server user is returned. For data from a database connection, the database user is returned. When no user is associated with the workspace, such as a file geodatabase, an empty string will be returned.
Parameters
- portalObject: Portal - A Portal from which to return the current user.
- username (Optional): Text - The username of the user you want to return. Only limited information will be returned based on your permissions when making the request.
Return value: Dictionary
Returns a dictionary described by the properties below.
- email: Text - The email address associated with the user's account.
- fullName: Text - The user's first and last name.
- groups: Array<Text> - An array of groups that the user belongs to.
- id: Text - The user id of the returned user.
- privileges: Array<Text> - An array of privileges that the user has within their organization (e.g. edit, view, etc).
- role: Text - The role that the user plays within their organization (e.g. Administrator, Publisher, User, Viewer, or Custom).
- username: Text - The username of the returned user.
Example
Returns the dictionary for the user currently logged in based on the workspace connection from the given portal.
GetUser(Portal('https://www.arcgis.com'))
GetUser(features, username?) -> Dictionary
Profiles: Attribute Rules | Dashboard Data | Popups | Field Calculation | Form Calculation | Tasks
Returns the current user from the workspace. For data from a service, either the Portal user or Server user is returned. For data from a database connection, the database user is returned. When no user is associated with the workspace, such as a file geodatabase, an empty string will be returned.
Parameters
- features: FeatureSet - A FeatureSet from which to return the current user.
- username (Optional): Text - The username of the user you want to return. Only limited information will be returned based on your permissions when making the request.
Return value: Dictionary
Returns a dictionary described by the properties below.
- id: Text - The user id of the returned user.
- username: Text - The username of the returned user.
- fullName: Text - The user's first and last name.
- email: Text - The email address associated with the user's account.
- groups: Array<Text> - An array of groups that the user belongs to.
- role: Text - The role that the user plays within their organization (e.g. Administrator, Publisher, User, Viewer, or Custom).
- privileges: Array<Text> - An array of privileges that the user has within their organization (e.g. edit, view, etc).
Example
Returns information about the user "tester".
GetUser($layer, "tester")
// returns {"id": "12", "username": "tester", "name":"Testy Tester", "email": "tester@example.com", ...}
GetUser(portalObject, extensions?) -> Dictionary
Profiles: Attribute Rules | Popups | Field Calculation | Form Calculation | Tasks
Returns the current user from the workspace. For data from a service, either the Portal user or Server user is returned. For data from a database connection, the database user is returned. When no user is associated with the workspace, such as a file geodatabase, an empty string will be returned.
Parameters
- portalObject: Portal - A Portal from which to return the current user.
- extensions (Optional): Boolean - Determines if the
userLicenseTypeExtensions
will be returned in the dictionary.
Return value: Dictionary
Returns a dictionary described by the properties below.
- id: Text - The user id of the returned user.
- username: Text - The username of the returned user.
- fullName: Text - The user's first and last name.
- email: Text - The email address associated with the user's account.
- groups: Array<Text> - An array of groups that the user belongs to.
- role: Text - The role that the user plays within their organization (e.g. Administrator, Publisher, User, Viewer, or Custom).
- privileges: Array<Text> - An array of privileges that the user has within their organization (e.g. edit, view, etc).
- userLicenseTypeExtensions: Array<Text> - An array of the license type extensions associated with the user's account (e.g. "Utility Network", "Parcel Fabric", etc). The
extensions
parameter must be set totrue
in order for this to be returned.
Example
Returns information about the user currently logged in based on the portal with user extensions.
GetUser(Portal('https://www.arcgis.com', true)
GetUser(features, extensions?) -> Dictionary
Profiles: Attribute Rules | Popups | Field Calculation | Form Calculation | Tasks
Returns the current user from the workspace. For data from a service, either the Portal user or Server user is returned. For data from a database connection, the database user is returned. When no user is associated with the workspace, such as a file geodatabase, an empty string will be returned.
Parameters
- features: Portal - A FeatureSet or Portal from which to return the current user.
- extensions (Optional): Boolean - Determines if the
userLicenseTypeExtensions
will be returned in the dictionary.
Return value: Dictionary
Returns a dictionary described by the properties below.
- id: Text - The user id of the returned user.
- username: Text - The username of the returned user.
- fullName: Text - The user's first and last name.
- email: Text - The email address associated with the user's account.
- groups: Array<Text> - An array of groups that the user belongs to.
- role: Text - The role that the user plays within their organization (e.g. Administrator, Publisher, User, Viewer, or Custom).
- privileges: Array<Text> - An array of privileges that the user has within their organization (e.g. edit, view, etc).
- userLicenseTypeExtensions: Array<Text> - An array of the license type extensions associated with the user's account (e.g. "Utility Network", "Parcel Fabric", etc). The
extensions
parameter must be set totrue
in order for this to be returned.
Example
Returns information about the user currently logged in based on the workspace connection from a layer with user extensions.
GetUser($layer, true)
GroupBy
GroupBy(features, groupByFields, statistics) -> FeatureSet
Profiles: Attribute Rules | Dashboard Data | Field Calculation | Form Calculation | Popups | Tasks
Returns statistics as a FeatureSet for a set of grouped or distinct values.
Parameters
-
features: FeatureSet - A FeatureSet from which to return statistics for unique values returned from a given set of fields and/or expressions.
-
groupByFields: Text | Array<Text> | Array<Dictionary> - The field(s) and/or expression(s) from which to group statistics by unique values. This parameter can be a single field name, an array of field names, or an array of objects that specify column names paired with an expression (typically the field name) for the output FeatureSet. If an array of objects is specified, the following specification must be followed for each object:
-
statistics: Dictionary | Array<Dictionary> - The summary statistics to calculate for each group. This parameter can be a dictionary or array of dictionary that specify output statistics to return for each group. The following specification must be used:
Possible Values: SUM | COUNT | MIN | MAX | AVG | STDEV | VAR
Return value: FeatureSet
Examples
Returns the count of each tree type
var treeStats = GroupBy($layer, 'TreeType', { name: 'NumTrees', expression: '1', statistic: 'COUNT' });
// treeStats contains features with columns TreeType and NumTrees
// Each unique tree type will have a count
Returns the count and the average height of each tree type
var treeStats = GroupBy($layer,
[ // fields/expressions to group statistics by
{ name: 'Type', expression: 'TreeType'},
{ name: 'Status', expression: 'TreeStatus'}
],
[ // statistics to return for each unique category
{ name: 'Total', expression: '1', statistic: 'COUNT' },
{ name: 'AvgHeight', expression: 'Height', statistic: 'AVG' },
{ name: 'MaxPercentCoverage', expression: 'CoverageRatio * 100', statistic: 'MAX' }
]
);
// treeStats contains features with columns Type, Status, Total, AvgHeight, MaxPercentCoverage
// Each unique tree type (combination of type and status) will have a count, average height, and maximum value of percent coverage
Guid
Guid(guidFormat?) -> Text
Returns a random GUID as a string.
Parameter
- guidFormat (Optional): Text - An named format for the GUID. The default value is
digits-hyphen-braces
.
Possible Values: digits / digits-hyphen / digits-hyphen-braces / digits-hyphen-parentheses
Return value: Text
Examples
Returns a value similar to {db894515-ed21-4df1-af67-36232256f59a}
Guid()
Returns a value similar to d00cf4dffb184caeb8ed105b2228c247
Guid('digits')
Hash
Hash(value) -> Number
Generates a hash code value for the given variable.
Parameter
- value: Text | Number | Boolean | Date | Array<Any> | Dictionary | Geometry - The variable to be hashed.
Return value: Number
Example
Returns 1649420691
.
Hash('text value')
HasKey
HasKey(value, key) -> Boolean
Indicates whether a dictionary or feature has the input key.
Parameters
- value: Dictionary | Feature - The dictionary or feature to check for a key or field name.
- key: Text - The key or field name to check.
Return value: Boolean
Example
prints true
var d = Dictionary('Port Hope', 16214, 'Grafton', '<1000', 'Cobourg', 18519);
HasKey(d, 'Cobourg');
Includes
Includes(inputArray, value) -> Boolean
Determines whether an array contains a given value. Returns true
if the value is found within the array.
Parameters
Return value: Boolean
Examples
Returns true
.
Includes(['orange', 'purple', 'gray'], 'purple')
Returns false
.
Includes(['orange', 'purple', 'gray'], 'red')
IndexOf
IndexOf(inputArray, item) -> Number
Returns the zero-based index location of the input item in an array. If item
does not exist, then -1
is returned.
Parameters
Return value: Number
Example
prints 2
var num = [1,2,3,4];
return indexof(num, 3);
Insert
Insert(inputArray, index, value) -> Null
Inserts a new value into an array at a given index. Existing elements positioned at or above the given index will shift up one index value. The array increases in size by one.
Parameters
- inputArray: Array<Any> - The array to insert the new value into.
- index: Number - The index of the array where the new value should be inserted. An index of 0 will insert the value at the beginning of the array. An index that equals the size of the array will insert the value at the end of the array. An index greater than the size of the array will cause an error. If a negative index is provided, it will be used as an offset from the end of the array.
- value: Any - The value to insert into the array.
Return value: Null
Examples
var colors = ['orange', 'purple', 'gray']
Insert(colors, 1, 'yellow')
// colors = ['orange','yellow','purple','gray']
var colors = ['orange', 'purple', 'gray']
Insert(colors, -1, 'yellow')
// colors = ['orange','purple','yellow','gray']
IsEmpty
IsEmpty(value) -> Boolean
Returns true
if the provided value is null
or an empty string (e.g. ''
). Returns false
for all other cases, including empty arrays and dictionaries.
Parameter
- value: Any - The value that is compared against
null
or''
. This may be a value of any type.
Return value: Boolean
Examples
// Returns true
IsEmpty(null)
// Returns false
IsEmpty('hello world')
IsNan
IsNan(value) -> Boolean
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
Parameter
- value: Any - The value to check if it is NaN.
Return value: Boolean
Examples
// Returns true
IsNan(Infinity / Infinity)
// Returns false
IsNan('4')
Map
Map(inputArray, mappingFunction) -> Array<Any>
Creates a new array based on results of calling a provided function on each element in the input array.
Parameters
-
mappingFunction: Function - The function to call on each element in the array
mappingFunction(value: Any) -> Any
. The function must return a new item that will be part of the returned array. The function can be a user-defined function or a core Arcade function defined with the following parameter:- value: Any - Represents the value of an element in the array.
Return value: Array<Any>
The items returned by the mapping function.
Examples
Converts all of the elements in the array from Fahrenheit to Celsius and returns them in a new array.
// This function will take in values from the input array and convert them to Celsius
function toCelsius(f) {
return Round((f - 32) * 5/9, 2) }
}
// The toCelsius function executes for each each item
// in the input array.
// Map returns the resulting array of converted values.
Map([82, 67, 96, 55, 34], toCelsius)
// returns [27.78, 19.44, 35.56, 12.78, 1.11]
Converts date objects to formatted text
var dates = [ Date(1996, 11, 10), Date(1995, 1, 6), Date(1992, 2, 27), Date(1990, 10, 2)];
function formatDates(dateVal) { return Text(dateVal, 'MMM D, Y') }
Map(dates, formatDates);
// returns ['Dec 10, 1996', 'Feb 6, 1995', 'Mar 27, 1992', 'Nov 2, 1990']
NextSequenceValue
NextSequenceValue(sequenceName) -> Number
Profiles: Attribute Rule Calculation
Returns the next sequence value from the database sequence specified. If inputSequenceName
does not exist, the expression will error.
Parameter
- sequenceName: Text - The name of the sequence. This must already be configured in the database.
Return value: Number
Example
Returns a number with the next sequence value
NextSequenceValue('PipeIDSeq')
None
None(inputArray, testFunction) -> Boolean
Tests whether none of the elements in a given array pass a test from the provided function. Returns true
if the testFunction
returns false
for all items in the input array.
Parameters
-
testFunction: Function - The function to test each element in the array
testFunction(value: Any) -> Boolean
. The function must return a falsy value if the element doesn't pass the test. The function can be a user-defined function or a core Arcade function defined with the following parameter:- value: Any - Represents the value of an element in the array.
Return value: Boolean
true
if all the elements in the array don't pass the test function.
Examples
Returns false
because some of the elements in the input array pass the isEven
test
// isEven is used to test if each element in the array is even
// it returns true if the element is divisible by two, false if is not
function isEven(value) { return value % 2 == 0 }
// The isEven function will execute for each element in the array,
// returning the following values: false, true, false, true, false
// Since at least one value in the array passed the test
// (return true), the return value will be false
None([1,2,3,4,5], isEven)
Uses the existing isEmpty
Arcade function as the testFunction
. This is valid because isEmpty
takes a single parameter and returns a boolean value. This expression returns true
if none of the fields are empty.
var myArray = [ $feature.field1, $feature.field2, $feature.field3, $feature.field4];
None(myArray, isEmpty)
Number
Number(value, pattern?) -> Number
Parses the input value to a number.
Parameters
-
value: Any - The value to convert to a number.
-
pattern (Optional): Text - The format pattern string used to parse numbers formatted in a localized context from a string value to a number. Sepcial characters to define the pattern:
- 0: Mandatory digits
- #: Optional digits
- %: Divide by 100
Return value: Number
Examples
Parses a number using a grouping separator appropriate for the local in which the expression is executed
Number('1,365', ',###') // returns 1365
Remove strings from number.
Number('abc10def', 'abc##def') // return 10
Specify minimum digits past 0 as two and maximum digits past 0 as 4.
Number('10.456','00.00##') // returns 10.456
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.
Number('10.4','00.00##') // returns NaN
Indicate the size of the repeated group and the final group size of the input value.
Number('12,12,456', ',##,###') // returns 1212456
If there is a negative subpattern, it serves only to specify the negative prefix and suffix.
Number('-12,23,345', ',##,###;-,##,###') // returns -1223345
Divide by 100. Maximum of three decimal places can be input.
Number('99.99%', '#.##%') // 0.9999
OrderBy
OrderBy(features, sqlExpression) -> FeatureSet
Profiles: Attribute Rules | Dashboard Data | Popups | Field Calculation | Form Calculation | Tasks
Orders a FeatureSet by using a SQL92 OrderBy clause.
Parameters
- features: FeatureSet - The FeatureSet, or layer, to order.
- sqlExpression: Text - The SQL92 expression used to order features in the layer.
Return value: FeatureSet
Examples
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')
Pop
Pop(inputArray) -> Any
Removes and returns the element at the end of the array. If the array is empty, then an error is thrown.
Parameter
Return value: Any
Example
Returns 'gray'. The input array will now equal ['orange', 'purple']
.
Pop(['orange', 'purple', 'gray'])
Portal
Portal(url) -> Portal
Profiles: Field Calculation | Form Calculation | Popups | Tasks
Creates a reference to an ArcGIS Portal.
Parameter
- url: Text - The url of the portal.
Return value: Portal
Examples
Query features from a portal item in ArcGIS Online
var arcgisPortal = Portal('https://www.arcgis.com');
var features = FeatureSetByPortalItem(arcgisPortal, '7b1fb95ab77f40bf8aa09c8b59045449', 0, ['Name', 'Count'], false);
Enterprise Portal
Portal('https://www.example.com/arcgis')
Push
Push(inputArray, value) -> Number
Adds an element to the end of an array and returns the new length of the array.
Parameters
- inputArray: Array<Any> - The array to have elements pushed to.
- value: Any - The value to add as the last element of the input array.
Return value: Number
Example
Returns 4. The input array will now equal ['orange', 'purple', 'gray', 'red']
.
Push(['orange', 'purple', 'gray'], 'red').
Reduce
Reduce(inputArray, reducerFunction, initialValue?) -> Any
Executes a provided "reducer" function on each element in the array, passing in the return value from the calculation of the previous element.
Parameters
-
reducerFunction: Function - The reducer function that will aggregate the array values
reducerFunction(previousValue: Any, arrayValue: Any) -> Any
. -
initialValue (Optional): Any - An item to pass into the first argument of the reducer function.
Return value: Any
The value that was assembled by the reducer function for each element in the array.
Examples
Without the initialValue
parameter, the first two elements of the cities
array are passed into the add function as arguments.
var cities = [{
name: 'Columbus',
pop: 913921
}, {
name: 'Cincinnati',
pop: 307266
}, {
name: 'Dayton',
pop: 140343
}, {
name: 'Cleveland',
pop: 376599
}];
// the first time this function is called it will take the first two elements of the array as x and y
// The subsequent times the function is executed, it will take the return value
// from the previous function call as x and the next array value as y
function mostPopulated(city1, city2) {
IIf (city1.pop > city2.pop, city1, city2)
}
var largestCity = Reduce(cities, mostPopulated)
Console(largestCity.name + ' is the biggest city in the list with a population of ' + largestCity.pop)
// Columbus is the biggest city in the list with a population of 913921
Since the initialValue
parameter is set, that value will be the function's first argument (city1
), and the first element of the cities
will be the function's second argument (city2
).
var los_angeles = { name: 'Los Angeles', pop: 3898747 }
// since an initialValue is provided, it will be passed into the maxPop function as x
// and the first value of the array will be passed in as y for the initial function call
// The subsequent times the function is executed, it will take the return value
// from the previous function call as x and the next array value as y
var largestCity = Reduce(cities, mostPopulated, los_angeles)
Console(largestCity.name + ' is the biggest city in the list with a population of ' + largestCity.pop)
// Los Angeles is the biggest city in the list with a population of 3898747
Resize
Resize(inputArray, newSize, value?) -> Null
Changes the number of elements in an array to the specified size. It can be used to expand the array or truncate it early. After resizing, attempting to index beyond the new last element will result in an error, except for the case of indexing the next element, which will continue to expand the array by one element.
Parameters
- inputArray: Array<Any> - The array to be resized.
- newSize: Number - The number of elements desired in the resized array.
- value (Optional): Any - The optional value that will be used for any new elements added to the array. If no value is specified, the newly added elements will have a
null
value.
Return value: Null
Examples
Returns ['orange', 'purple', 'gray', null, null]
var colors = ['orange', 'purple', 'gray']
Resize(colors, 5)
return colors
Returns ['orange', 'purple', 'gray', 'red', 'red']
var colors = ['orange', 'purple', 'gray']
Resize(colors, 5, 'red')
return colors
Returns ['orange']
var colors = ['orange', 'purple', 'gray']
Resize(colors, 1)
return colors
Reverse
Reverse(inputArray) -> Array<Any>
Reverses the contents of the array in place.
Parameter
Example
Returns ['gray', 'purple', 'orange']
Reverse(['orange', 'purple', 'gray'])
Schema
This function has 2 signatures:
Schema(inputFeature) -> Dictionary
Profiles: Attribute Rules | Dashboard Data | Popups | Field Calculation | Form Calculation | Velocity | Tasks
Returns the schema description of the provided Feature.
Parameter
- inputFeature: Feature - The feature whose schema to return.
Return value: Dictionary
Returns a dictionary described by the properties below.
- fields: Array<Dictionary> - Returns an array of dictionaries describing the fields in the Feature. Each dictionary describes the field
name
,alias
,type
,subtype
,domain
,length
, and whether it iseditable
andnullable
. - geometryType: Text - The geometry type of features in the Feature. Returns
esriGeometryNull
for tables with no geometry.
Possible values: esriGeometryPoint
, esriGeometryLine
, esriGeometryPolygon
, esriGeometryNull
- globalIdField: Text - The global ID field of the Feature. Returns
""
if not globalId-enabled. - objectIdField: Text - The objectId field of the Feature.
Schema(features) -> Dictionary
Profiles: Attribute Rules | Dashboard Data | Popups | Field Calculation | Form Calculation | Velocity | Tasks
Returns the schema description of the provided FeatureSet.
Parameter
- features: FeatureSet - The FeatureSet whose schema to return.
Return value: Dictionary
Returns a dictionary described by the properties below.
- objectIdField: Text - The objectId field of the FeatureSet.
- globalIdField: Text - The global ID field of the FeatureSet. Returns
""
if not globalId-enabled. - geometryType: Text - The geometry type of features in the FeatureSet. Returns
esriGeometryNull
for tables with no geometry.
Possible values: esriGeometryPoint
, esriGeometryLine
, esriGeometryPolygon
, esriGeometryNull
- fields: Array<Dictionary> - Returns an array of dictionaries describing the fields in the FeatureSet. Each dictionary describes the field
name
,alias
,type
,subtype
,domain
,length
, and whether it iseditable
andnullable
.
Slice
Slice(inputArray, startIndex?, endIndex?) -> Array<Any>
Returns a portion of an array between two indexes as a new array.
Parameters
- inputArray: Array<Any> - The array to be sliced.
- startIndex (Optional): Number - The index from which to start the slice. Defaults to
0
. If a negative index is provided, it will be used as an offset from the end of the array. - endIndex (Optional): Number - The index where the slice will end. The value at this index will not be included in the returned array. Defaults to the array size.
Examples
Returns ['purple', 'gray']
Slice(['orange', 'purple', 'gray', 'red', 'blue'], 1, 3)
Returns ['red', 'blue']
Slice(['orange', 'purple', 'gray', 'red', 'blue'], 3)
Returns ['orange', 'purple', 'gray', 'red', 'blue']
Slice(['orange', 'purple', 'gray', 'red', 'blue'])
Returns ['blue']
Slice(['orange', 'purple', 'gray', 'red', 'blue'], -1)
Sort
Sort(inputArray, comparatorFunction?) -> Array<Any>
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.
Parameters
- inputArray: Array<Any> - The array to sort.
- comparatorFunction (Optional): Function - A user defined function to be used for the sort
orderingFunction(a: Any, b: Any) -> Number
. The function receives two elements and should retun a number that indicates the sorting order of the two elements:
> 0
: sort b
before a
= 0
: keep the original order of a
and b
< 0
: sort a
before b
Examples
returns ['$', 1, 'A', 'a']
Sort([1, 'a', '$', 'A'])
Sort using a user defined function
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);
// returns '[{ 'AGE': 24, 'NAME': 'Emma' }, { 'AGE': 25, 'NAME': 'Sam' }, { 'AGE': 27, 'NAME': 'Bob' } ]'
Splice
Splice(value1, [value2, ..., valueN]?) -> Array<Any>
Concatenates all parameters together into a new array.
Parameters
- value1: Any - A value to be spliced into a new array.
- [value2, ..., valueN] (Optional): Any - Ongoing values to be spliced into a new array.
Examples
Returns ['orange', 'purple', 1, 2, 'red']
Splice(['orange', 'purple'], 1, 2, 'red')
Returns [1, 2, 3, 4]
Splice([1,2], [3,4])
SubtypeCode
SubtypeCode(inputFeature) -> Number | Text | Date
Returns the subtype code for a given feature.
Parameter
- inputFeature: Feature - The Feature from which to get the subtype code.
Return value: Number | Text | Date
Example
Returns the code of the subtype
// feature has a field named `assetGroup`
// with the subtype described in the Subtypes function example
SubtypeCode($feature) // returns 1
SubtypeName
SubtypeName(inputFeature) -> Text
Returns the subtype name for a given feature.
Parameter
- inputFeature: Feature - The Feature from which to get the subtype name.
Return value: Text
Example
Returns the name of the subtype
// feature has a field named `assetGroup`
// with the subtype described in the Subtypes function example
SubtypeName($feature) // returns "Single Phase"
Subtypes
This function has 2 signatures:
Subtypes(inputFeature) -> Dictionary
Returns the subtype coded value Dictionary. Returns null
when subtypes are not enabled on the layer.
Parameter
- inputFeature: Feature - The Feature from which to get subtypes.
Return value: Dictionary
Returns a dictionary described by the properties below.
- subtypeField: Text - The field containing a subtype.
- subtypes: Array<Dictionary> - An array of dictionaries describing the subtypes. Each dictionary has a
code
property, which contains the actual field value, and aname
property containing a user-friendly description of the value (e.g.{ code: 1, name: "pavement" }
)
Example
Returns subtypes with coded values from a feature
Subtypes($feature)
// returns the following dictionary
// {
// subtypeField: 'assetGroup',
// subtypes: [
// { name: "Unknown", code: 0 },
// { name: "Single Phase", code: 1 },
// { name: "Two Phase", code: 2 }
// ]
// }
Subtypes(features) -> Dictionary
Returns the subtype coded value Dictionary. Returns null
when subtypes are not enabled on the layer.
Parameter
- features: FeatureSet - The FeatureSet from which to get subtypes.
Return value: Dictionary
Returns a dictionary described by the properties below.
- subtypeField: Text - The field containing a subtype.
- subtypes: Array<Dictionary> - An array of dictionaries describing the subtypes. Each dictionary has a
code
property, which contains the actual field value, and aname
property containing a user-friendly description of the value (e.g.{ code: 1, name: "pavement" }
)
Example
Returns subtypes with coded values from a FeatureSet
var fsTransformer = FeatureSetByName($layer, "Transformer")
Subtypes(fsTransformer)
// returns the following dictionary
// {
// subtypeField: 'assetGroup',
// subtypes: [
// { name: "Unknown", code: 0 },
// { name: "Single Phase", code: 1 },
// { name: "Two Phase", code: 2 }
// ]
// }
ToHex
ToHex(value) -> Text
Converts an integer to a hexidecimal representation.
Parameter
- value: Number - The value to be converted to a hexidecimal value.
Return value: Text
Examples
Returns "64"
.
ToHex(100)
Returns the hexidecimal representation for the color royal blue, "#4169E1"
, from its RGB values
var r = ToHex(65); // returns "41"
var g = ToHex(105); // returns "69"
var b = ToHex(225); // returns "E1"
Concatenate("#",r,g,b)
// Returns "#4169E1"
Top
This function has 2 signatures:
Top(inputArray, numItems) -> Array<Any>
Truncates the input array and returns the first given number of elements.
Parameters
- inputArray: Array<Any> - The array to truncate.
- numItems: Number - The number of items to return from the beginning of the array.
Example
returns [ 43,32,19 ]
Top([ 43,32,19,0,3,55 ], 3)
Top(features, numItems) -> FeatureSet
Truncates the FeatureSet and returns the first given number of features.
Parameters
- features: FeatureSet - The FeatureSet to truncate.
- numItems: Number - The number of features to return from the beginning of the FeatureSet.
Return value: FeatureSet
Example
Returns the top 5 features with the highest population
Top( OrderBy($layer, 'POPULATION DESC'), 5 )
TypeOf
TypeOf(value) -> Text
Returns the type of the input value. Will return one of the following types: Array, Date, Text, Boolean, Number, Dictionary, Feature, FeatureSet, Point, Polygon, Polyline, Multipoint, Extent, Function, Unrecognized Type.
Parameter
- value: Any - The input value, variable, or feature attribute.
Return value: Text
Examples
prints 'Boolean'
TypeOf(true)
prints 'Date'
TypeOf(Now())