Field

AMD: require(["esri/layers/support/Field"], (Field) => { /* code goes here */ });
ESM: import Field from "@arcgis/core/layers/support/Field.js";
Class: esri/layers/support/Field
Inheritance: Field Accessor
Since: ArcGIS Maps SDK for JavaScript 4.0

Information about each field in a layer. Field objects must be constructed when creating a FeatureLayer from client-side graphics. This class allows you to define the schema of each field in the FeatureLayer. Note that you do not need to add fields to the constructor of a FeatureLayer loaded from a service since they are already defined by the service. See the sample below for more information about using this module.

See also
Example
// Each object in this array is autocast as
// an instance of esri/layers/support/Field
let fields = [
  {
    name: "ObjectID",
    alias: "ObjectID",
    type: "oid"
  }, {
    name: "title",
    alias: "title",
    type: "string"
  }, {
    name: "type",
    alias: "type",
    type: "string"
  }, {
    name: "mag",
    alias: "Magnitude",
    type: "double"
}];

// add the array of fields to a feature layer
// created from client-side graphics
featureLayer.set({
  fields: fields,
  objectIdField: "ObjectID"
});

Constructors

Field

Constructor
new Field(properties)
Parameter
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
Show inherited properties Hide inherited properties
Name Type Summary Class

The display name for the field.

Field

The name of the class.

Accessor

The default value set for the field.

Field

Contains information describing the purpose of each field.

Field

The domain associated with the field.

Field

Indicates whether the field is editable.

Field

The field length.

Field

The name of the field.

Field

Indicates if the field can accept null values.

Field

The data type of the field.

Field

The types of values that can be assigned to a field.

Field

Property Details

alias

Property
alias String

The display name for the field.

Default Value:null

declaredClass

Inherited
Property
declaredClass Stringreadonly
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.7 Accessor since 4.0, declaredClass added at 4.7.

The name of the class. The declared class name is formatted as esri.folder.className.

defaultValue

Property
defaultValue Number |String |null |undefined
Since: ArcGIS Maps SDK for JavaScript 4.9 Field since 4.0, defaultValue added at 4.9.

The default value set for the field.

Default Value:undefined

description

Property
description String
Since: ArcGIS Maps SDK for JavaScript 4.12 Field since 4.0, description added at 4.12.

Contains information describing the purpose of each field.

The domain associated with the field. Domains are used to constrain the values allowed in a field. There are two types of domains: RangeDomain and CodedValueDomain.

Default Value:null
Example
// print out the coded domain values when the layer is loaded
const layerView = await view.whenLayerView(featureLayer)
await reactiveUtils.whenOnce(() => !layerView.updating);

featureLayer.fields.forEach((field) => {
  if (!field.domain) {
    return;
  }

  let domain = field.domain
  console.log(field.name, domain.type, domain.name);

  if (domain.type === "coded-value"){
    domain.codedValues.forEach((codeValue) => {
      console.log("name:", codeValue.name, "code:", codeValue.code);
    });
  }
});

editable

Property
editable Boolean

Indicates whether the field is editable.

Default Value:true

length

Property
length Number |undefined

The field length.

Default Value:undefined

name

Property
name String

The name of the field.

Default Value:null

nullable

Property
nullable Boolean

Indicates if the field can accept null values. Requires ArcGIS Server version 10.1 or greater.

Default Value:true

type

Property
type String

The data type of the field.

Notes

  • Support for big-integer, date-only, time-only and timestamp-offset fields was added in beta for FeatureLayer and MapImageLayer at version 4.28.
  • The big-integer field type is in beta and may not be fully supported in the JavaScript API.
  • The JavaScript API only supports safe integers that fall between -9007199254740991 (minimum) and 9007199254740991 (maximum). Numbers that fall outside of this range will be incorrect due to rounding, resulting in graphical or performance issues. For example, a calculation using Arcade expressions that results in a value exceeding these safe integers may be incorrect since rounding can occur.
  • Web applications can only edit whole numbers between -9007199254740991 and 9007199254740991.

Possible Values:"small-integer" |"integer" |"big-integer" |"single" |"double" |"long" |"string" |"date" |"date-only" |"time-only" |"timestamp-offset" |"oid" |"geometry" |"blob" |"raster" |"guid" |"global-id" |"xml"

Default Value:null
See also

valueType

Property
valueType String
Since: ArcGIS Maps SDK for JavaScript 4.12 Field since 4.0, valueType added at 4.12.

The types of values that can be assigned to a field. See the table below for a list of possible values.

Mode Description
name-or-title Text that represents a name, title, label, or keyword for each feature.
description Text that provides a longer description of the feature, more than just a name or title.
type-or-category Types or categories that group features based on common characteristics.
count-or-amount Integers (no decimal) that represent how many or how much there is of a specific attribute.
percentage-or-ratio Number values in this field reflect the relationship between different quantities.
measurement A number that reflects a characteristic that you can precisely measure.
unique-identifier The values in this field are used to positively distinguish one feature or entity from another.
ordered-or-ranked The values in this field represent a feature's status in an ordered or ranked list. For example, a feature could be one of the following: Small, medium, large, First, second, third, fourth, or Informational, warning, error, failure.
binary Only one of two values are possible for each feature. Some examples include the following: On or off, Yes or no, True or false, or Inhabited or vacant.
location-or-place-name Values in this field represent a geographic location. Examples of values in such a field include a street address, city name, region, building name (such as A.K. Smiley Public Library), attraction name (such as Alameda County Fairgrounds or Cairngorms National Park), postal code, or country.
coordinate These fields store a geographic coordinate value such as x, y, z, latitude, or longitude.
date-and-time Values in this field store explicit dates and times or date references such as days of the week, months, or years.
none No specified type.

Possible Values:"binary" |"coordinate" |"count-or-amount" |"date-and-time" |"description" |"location-or-place-name" |"measurement" |"name-or-title" |"none" |"ordered-or-ranked" |"percentage-or-ratio" |"type-or-category" |"unique-identifier"

Method Overview

Show inherited methods Hide inherited methods
Name Return Type Summary Class

Adds one or more handles which are to be tied to the lifecycle of the object.

Accessor
*

Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product.

Field

Returns true if a named group of handles exist.

Accessor

Removes a group of handles owned by the object.

Accessor

Converts an instance of this class to its ArcGIS portal JSON representation.

Field

Method Details

addHandles

Inherited
Method
addHandles(handleOrHandles, groupKey)
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, addHandles added at 4.25.

Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.

// Manually manage handles
const handle = reactiveUtils.when(
  () => !view.updating,
  () => {
    wkidSelect.disabled = false;
  },
  { once: true }
);

this.addHandles(handle);

// Destroy the object
this.destroy();
Parameters
handleOrHandles WatchHandle|WatchHandle[]

Handles marked for removal once the object is destroyed.

groupKey *
optional

Key identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.

fromJSON

Method
fromJSON(json){*}static

Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product. The object passed into the input json parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.

Parameter
json Object

A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.

Returns
Type Description
* Returns a new instance of this class.

hasHandles

Inherited
Method
hasHandles(groupKey){Boolean}
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, hasHandles added at 4.25.

Returns true if a named group of handles exist.

Parameter
groupKey *
optional

A group key.

Returns
Type Description
Boolean Returns true if a named group of handles exist.
Example
// Remove a named group of handles if they exist.
if (obj.hasHandles("watch-view-updates")) {
  obj.removeHandles("watch-view-updates");
}

removeHandles

Inherited
Method
removeHandles(groupKey)
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25 Accessor since 4.0, removeHandles added at 4.25.

Removes a group of handles owned by the object.

Parameter
groupKey *
optional

A group key or an array or collection of group keys to remove.

Example
obj.removeHandles(); // removes handles from default group

obj.removeHandles("handle-group");
obj.removeHandles("other-handle-group");

toJSON

Method
toJSON(){Object}

Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.

Returns
Type Description
Object The ArcGIS portal JSON representation of an instance of this class.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.