Calculate (Feature Service/Layer)

Description

The calculate operation is performed on a feature service layer resource. It updates the values of one or more fields in an existing feature service layer based on SQL expressions or scalar values. The calculate operation can only be used if the supportsCalculate property of the layer is true.

If supportsCalculate is true and isDataVersioned is also true, then the gdbVersion parameter is supported. If supportsCalculate is true and isDataBranchVersioned is also true then the sessionID and returnEditMoment parameters are supported.

NoteNote:

To support calculate with versioned data, the feature service must be published from ArcGIS Pro referencing a registered data source.

Neither the Shape field nor system fields can be updated using calculate. System fields include ObjectId and GlobalId.

See Calculate a field for more information on supported expressions.

Request parameters

Parameter

Details

where

Description: A where clause can be used to limit the updated records. Any legal SQL where clause operating on the fields in the layer is allowed.

Examples:

where=POP2000 > 350000

where=CITY_NAME = 'Glendora'

If you are working with ArcGIS Server 10.4 or a subsequent version, the dateFieldsTimezoneID property of the feature service identifies the time zone all dates are stored in. If your where clause is referencing a date type field and you have dateFieldsTimezoneID set to a specific time zone, make sure your where clause issues the time in that specific time zone. For example, if you want to limit the records being updated to match 1 pm on February 9th, 2015, Pacific Standard Time, your where clause would be:

where=pacific_time_date_field = DATE '2015-02-09 13:00:00'

You can set the dateFieldsTimezoneID property in the ArcMap Service Editor, Parameters tab, when you publish the service. If you don't have dateFieldsTimezoneID set, be sure your where clause issues the time you are querying in UTC. The dateFieldsTimezoneID property does not apply to fields that were time enabled through the Layer Properties Time tab in ArcMap at the time of publishing.

calcExpression

Description: The array of field/value info objects that contain the field or fields to update and their scalar values or SQL expression. For more information on how to build expressions, see Calculate a field.

Syntax: "calcExpression":[{"field" : <fieldname>, "value" | "sqlExpression": <value> | "expression"},...]

Examples:

"calcExpression":[{"field" : "Quality", "value" : 3}]

"calcExpression":[{"field" : "A", "sqlExpression" : "B*3"}]

If you are updating records in a date type field, be sure to issue the new date or time value in UTC. This is the case even if you have the dateFieldsTimezoneID property set and issue local time in your where clause.

NoteNote:

As of 10.6.1, calcExpression can take null values.

sqlFormat

Description: The SQL format for the calcExpression. The expression can take one of two formats. It can be either standard SQL92 (standard), or it can use the native SQL of the underlying datastore (native). The default is standard.

NoteNote:
The SQL format native is supported only for admin users and when useStandardizedQuery=false.

Values: standard | native

Values for date type fields must always be specified in UTC.

gdbVersion

Description: The geodatabase version to apply the edits. This parameter applies only if the isDataVersioned property of the layer is true.

Can be either a traditional version or a branch version.

If the gdbVersion parameter is not specified, edits are made to the published map's version.

Syntax: gdbVersion=<version>

Example: gdbVersion=SDE.DEFAULT

sessionID

Description: Optional parameter which is set by a client during long transaction editing on a branch version. The sessionID is a GUID value that clients establish at the beginning and use throughout the edit session. The sessonID ensures isolation during the edit session. This parameter applies only if the isDataBranchVersioned property of the layer is true.

Syntax: sessionID=<sessionID>

Example: sessionID={E81C2E2D-C6A7-40CB-BF61-FB499E53DD1D}

returnEditMoment

Description: Optional parameter specifying whether the response will report the time edits were applied. If returnEditMoment = true, the server will return the time edits were applied in the response's editMoment key. This parameter applies only if the isDataBranchVersioned property of the layer is true.

Values: true | false

Example: returnEditMoment=true

f

Description: The response format. The default response format is html.

Values: html | json

JSON response syntax

{
   "success" : <true|false>,
   "updatedFeatureCount" : <count>, 
   "editMoment": <epochMilliseconds>
}

JSON response example

{
   "success":true,
   "updatedFeatureCount":51
}

JSON response example (when data is branch versioned and returnEditMoment is true)

{
   "success":true,
   "updatedFeatureCount":51, 
   "editMoment": 1457994488000
}