FieldsIndex

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

This class provides convenient methods that can be used to make case-insensitive lookups for a field by its name. It also provides more information such as the list of date fields in a layer.

Constructors

FieldsIndex

Constructor
new FieldsIndex(properties)
Parameter
properties Object
optional

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

Property Overview

Name Type Summary Class
Field[]|Object[]

An array of date fields or field json objects.

FieldsIndex

Property Details

dateFields

Property
dateFields Field[]|Object[]

An array of date fields or field json objects.

Default Value:[]

Method Overview

Name Return Type Summary Class
Field

Returns a field with the specified field name.

FieldsIndex
String|null

Returns a time zone for a field.

FieldsIndex
Boolean

Checks if a field with the specified field name exists in the layer.

FieldsIndex
Boolean

Checks if a field with the specified field name is a date field.

FieldsIndex

Method Details

get

Method
get(fieldName){Field}

Returns a field with the specified field name.

Parameter
fieldName String

The name of the field. The name is case-insensitive.

Returns
Type Description
Field Returns a field with a given name.

getTimeZone

Method
getTimeZone(fieldOrFieldName){String|null}

Returns a time zone for a field. Use this method to ensure queries in the following places are issued in the time zone of the given date field:

The following table explains the value returned from this method:

Field type Returned value
Date field Returns the time zone associated with the date field. Returns unknown if the layer's date fields are in unknown time zone.
Date-only, Time-only or Timestamp-offset field Returns unknown as services do not have time zone associated with date-only, time-only and timestamp-offset fields. Date-only and time-only fields are time zone agnostic. Timestamp-offset field values store its time offset.
All other fields Returns null.
Parameter
fieldOrFieldName String|Field

The name of the field or the field instance.

Returns
Type Description
String | null Returns the time zone for the given date field name or date field instance.
Example
// Query for features that recorded on January 1, 2012 9:00:00 AM GMT
// DateTime_PST date field values are in PST. Must adjust the epoch values to PST

const queryDate = new Date(1325408400000); 01/01/2012 9:00:00 AM GMT
let queryFields = [layer.objectIdField, "DateTime_PST"];

// get the timezone of the DateTime_PST date field
const fieldTimeZone = layer.fieldsIndex.getTimeZone("DateTime_PST") ;

// we need to adjust the date value to match the time zone of the field.
const where = `DateTime_PST < DATE '${getDateForTimeZone(queryDate, fieldTimeZone)}'`
layerView.filter = new FeatureFilter({
  where
});
runQueries(where, queryFields);

// This function conveniently formats a dates in terms of the parsed time zone.
function getDateForTimeZone(queryDate, timezone) {

  // adjust the given date field to the timezone of the date field
  const zonedDate = new Date(
    queryDate.toLocaleString("en-US", {
      timeZone: timezone
    })
  );
  const pad = (value) => String(value).padStart(2, "0");
  const month = pad(zonedDate.getMonth() + 1);
  const day = pad(zonedDate.getDate())
  const year = zonedDate.getFullYear();
  const hour = pad(zonedDate.getHours());
  const minutes = pad(zonedDate.getMinutes());
  const seconds = pad(zonedDate.getSeconds());

  return `${year}-${month}-${day} ${hour}:${minutes}:${seconds}`;
}

has

Method
has(fieldName){Boolean}

Checks if a field with the specified field name exists in the layer.

Parameter
fieldName String

The name of the field. The name is case-insensitive.

Returns
Type Description
Boolean Returns true if the field exists otherwise returns false.

isDateField

Method
isDateField(fieldName){Boolean}

Checks if a field with the specified field name is a date field.

Parameter
fieldName String

The name of the field.

Returns
Type Description
Boolean Returns true if the field type is date otherwise returns false.

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