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: String

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: String
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( arrayOrString ) -> returns: Number

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

Name Type Description
arrayOrString Array / String An array or string on which to perform the operation.
Returns: Number
Example

Returns 6

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

Returns 13

Count('Graham County')

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 String 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: String

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

Name Type Description
feature Feature The feature with a field that has a domain.
fieldname String The name of the field (not the alias of the field) containing the domain.
value String The value to be converted back into a code.
subtype String 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: String
Example

prints the domain description for the field referenced.

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

DomainName

DomainName( feature, fieldname, code?, subtype? ) -> returns: String

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

Name Type Description
feature Feature The feature with a field that has a domain.
fieldname String The name of the field (not the alias of the field) containing the domain.
code String optional The code associated with the desired descriptive name. If not provided, the field value in the feature will be returned.
subtype String 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: String
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 String The first attribute's name.
value1 String / 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)


First

First( inputArray ) -> returns: *

Returns the first element in an array.

Name Type Description
inputArray Array The array from which to return the first feature.
Returns: *
Example

prints 'orange'

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

Guid

Guid( format? ) -> returns: String

Since version 1.3

Returns a random GUID as a string.

Name Type Description
format String 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: String
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 String 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);


NextSequenceValue

NextSequenceValue( inputSequenceName ) -> returns: Number

Since version 1.4

Profiles: Calculation

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 String 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 String 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%', '#.##%')

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 String 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: String

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 String optional Formatting string for dates or numbers. See the list of possible values below.

ValueDescription
0Digit
#Digit, omitting leading/trailing zeros
dDay of the week
DDay of the month
dddAbbreviated day of the week
ddddFull day of the week
MMonth number
MMMAbbreviated month name
MMMMFull month name
YYTwo-digit year
YFull year
h12-hour time (0-12)
H24-hour time (0-24)
mTwo digit minute
sTwo digit second
Returns: String
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( inputArray, numElements ) -> returns: Array

Since version 1.3

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

Name Type Description
inputArray Array The array to truncate.
numElements Number The number of elements to return from the beginning of the inputArray.
Returns: Array
Example
returns [ 43,32,19 ]
Top([ 43,32,19,0,3,55 ], 3)

TypeOf

TypeOf( value ) -> returns: String

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

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

prints 'Boolean'

TypeOf(true)

prints 'Date'

TypeOf(Now())


Feedback on this topic?