Skip To Content
ArcGIS Developer
Dashboard

Query Related Records (Map Service/Dynamic Layer)

  • URL:https://<dynamic-layer-url>/queryRelatedRecords
  • Required Capability:Data
  • Version Introduced:10.1

Description

The query-related records operation is performed on a dynamic layer / table resource, of type mapLayer. The result of this operation is one or more feature sets grouped by source layer / table object IDs. Each feature set contains feature objects including the values for the fields requested by the user. For related layers, if you request geometry information, the geometry of each feature is also returned in the feature set. For related tables, the feature set does not include geometries.

You can provide arguments to the query-related records operation as query parameters defined in the parameters table below.

Note:

All parameters related to geometry will be ignored when querying related tables.

New at 10.5

  • Supports datum transformation.

Request parameters

ParameterDetails
layer

(Required)

Defines a dynamic layer. Only dynamic map layers are supported. When using this parameter, keep the following in mind:

  • The id and definitionExpression properties are optional.
  • Use gdbVersion on a dynamic map layer definition to specify an alternate geodatabase version.

{
  "id": <layerOrTableId>, // optional
  "source": <layer source>, // only dynamic map layers are supported
  "definitionExpression": "<definitionExpression>" // optional
}

Example


{
  "id": 101,
  "source": {
    "type": "mapLayer",
    "mapLayerId": 0,
    "gdbVersion": "SDE.DynamicLayers"
  },
  "definitionExpression": "LotSize > 5000"
}
objectIds

The object IDs of this layer or table to be queried. Records related to these object IDs will be queried.

Syntax

objectIds=<objectId1>, <objectId2>

Example

objectIds=37, 462
relationshipId

The ID of the relationship to be queried. The relationships that this layer/table participates in are included in the Layer / Table Resource response. Records in tablesor layers corresponding to the related table or layer of the relationship are queried.

Example

relationshipsId=4
outFields

The list of fields from the related table or layer to be included in the returned feature set. This list is a comma-delimited list of field names. If you specify the shape field in the list of return fields, it is ignored. To request geometry, set returnGeometry to true. You can also specify the wildcard "*" as the value of this parameter. In this case, the results will include all the field values.

Example


outFields=AREANAME,ST,POP2000

//Wildcard usage
outFields=*
definitionExpression

The definition expression to be applied to the related table or layer. From the list of records that are related to the specified objectIds, only those records that conform to this expression will be returned.

Example

definitionExpression=POP2000 > 100000
returnGeometry

If true, the feature set includes the geometry associated with each feature. The default is true.

Note:

This parameter only applies to related layers. It will be ignored for related tables.

Values: true | false

maxAllowableOffset

Added at 10.0. Specifies the maxAllowableOffset to be used for generalizing geometries returned by the queryRelatedRecords operation. The maxAllowableOffset is in the units of the outSR. If outSR is not specified, maxAllowableOffset is assumed to be in the unit of the spatial reference of the map.

Example

maxAllowableOffset=2
geometryPrecision

Specifies the number of decimal places in the response geometries by the queryRelatedRecords operation. This applies to x- and y-values only (not m- or z-values).

Example

geometryPrecision=3
outSR

Specifies the spatial reference of the returned geometry. The spatial reference can be specified as a well-known ID or as a spatial reference json object. If outSR is not specified, the geometry is returned in the spatial reference of the map.

Note:

This parameter only applies to related layers. It will be ignored for related tables.

returnZ

If true, z-values will be included in the results if the features have z-values. Otherwise, z-values are not returned. The default is false.

Note:

This parameter only applies if returnGeometry is true.

Values: true | false

returnM

If true, m-values will be included in the results if the features have m-values. Otherwise, m-values are not returned. The default is false.

Note:

This parameter only applies if returnGeometry is true.

Values: true | false

datumTransformation

Added at 10.5. Applies a datum transformation while projecting geometries in the results when outSR is different than the layer's spatial reference.

Note:

When specifying a transformation, you need to think about which datum transformation is best applicable to project the layer (not the map service) to the outSR. The sourceSpatialReference property in the layer resource reports which spatial reference features are stored in the source dataset.

For a list of valid datum transformation ID values and well-known text strings, see Using spatial references. For more information on datum transformation, see the transformation parameter in the Project operation.

Syntax


datumTransformation=wkid1

datumTransformation={<dt1>}

Examples


//To apply a transformation
datumTransformation=1623

//To apply a composite transformation
datumTransformation={"geoTransforms":[{"wkid":108889,"transformForward":true},{"wkid":1622,"transformForward":false}]}
f

The response format. The default response format is html.

Values: html | json | pjson

Example usage

The following is a sample request URL for the queryRelatedRecords operation:

https://machine.domain.com/webadaptor/rest/services/Petroleum/KSPetro/MapServer/dynamicLayer/queryRelatedRecords?layer={"id":101,"definitionExpression":"\"sub_region\" like 'Pacific'","source":{"type":"mapLayer","mapLayerId":3}}&objectIds=3,4,5&relationshipId=2&returnGeometry=true&outFields=*&f=html

JSON Response syntax


{
  "geometryType": "<geometryType>", //if records include geometry
  "spatialReference": <spatialReference>, //if records include geometry
  "hasZ": <true|false>, //added in 10.1
  "hasM": <true|false>, //added in 10.1
  "fields": [
    {
      "name": "<fieldName1>",
      "type": "<fieldType1>",
      "alias": "<fieldAlias1>",
      "length": "<length1>"
    },
    {
      "name": "<fieldName2>",
      "type": "<fieldType2>",
      "alias": "<fieldAlias2>",
      "length": "<length2>"
    }
  ],
  "relatedRecordGroups": [
    {
      "objectId": <objectId1>,
      "relatedRecords": [ //features may include geometry for related layers only
        <relatedFeature11>,
        <relatedFeature12>
      ]
    },
    {
      "objectId": <objectId2>,
      "relatedRecords": [
        <relatedFeature21>,
        <relatedFeature22>
      ]
    }
  ]
}

JSON Response example

When viewing the JSON response for your request, keep the following in mind:

  • The domains member is not included in field information objects returned with the response.
  • The JSON response contains an optional property exceededTransferLimit. This property will be true only if the number of records exceeds the maximum number configured by an administrator.

{
  "geometryType": "esriGeometryPolygon",
  "spatialReference": {
    "wkid": 4267
  },
  "fields": [
    {
      "name": "OBJECTID", 
      "type": "esriFieldTypeOID", 
      "alias": "OBJECTID"
    }, 
    {
      "name": "FIELD_KID", 
      "type": "esriFieldTypeString", 
      "alias": "FIELD_KID", 
      "length": 25
    }, 
    {
      "name": "APPROXACRE", 
      "type": "esriFieldTypeDouble", 
      "alias": "APPROXACRE"
    }, 
    {
      "name": "FIELD_NAME", 
      "type": "esriFieldTypeString", 
      "alias": "FIELD_NAME", 
      "length": 150
    } 
  ],
  "relatedRecordGroups": [
    {
      "objectId": 3,
      "relatedRecords": [
        {
          "attributes": {
            "OBJECTID": 5540,
            "FIELD_KID": "1000147595",
            "APPROXACRE": 95929,
            "FIELD_NAME": "LOST SPRINGS",
          },
          "geometry": {
            "rings": [
              [
                [
                  -96.929599633999942,
                  38.52426809800005
                ],
                [
                  -96.929602437999961,
                  38.522448437000037
                ],
                [
                  -96.92959118999994,
                  38.529723252000053
                ],
                [
                  -96.929594022999936,
                  38.527905578000059
                ],
                [
                  -96.929596839999988,
                  38.526087119000067
                ],
                [
                  -96.929599633999942,
                  38.52426809800005
                ]
              ]
            ]
          }
        }
      ]
    }
  ]
}