Query Related Records (Map Service/Dynamic Layer)

URL:
https://<dynamic-layer-url>/queryRelatedRecords
Methods:
GET
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.

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.
Use dark colors for code blocksCopy
1
2
3
4
5
{
  "id": <layerOrTableId>, // optional
  "source": <layer source>, // only dynamic map layers are supported
  "definitionExpression": "<definitionExpression>" // optional
}

Example

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
{
  "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

Use dark colors for code blocksCopy
1
objectIds=<objectId1>, <objectId2>

Example

Use dark colors for code blocksCopy
1
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

Use dark colors for code blocksCopy
1
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

Use dark colors for code blocksCopy
1
2
3
4
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

Use dark colors for code blocksCopy
1
definitionExpression=POP2000 > 100000

returnGeometry

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

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

Use dark colors for code blocksCopy
1
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

Use dark colors for code blocksCopy
1
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.

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 .

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 .

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.

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

Use dark colors for code blocksCopy
1
2
3
datumTransformation=wkid1

datumTransformation={<dt1>}

Examples

Use dark colors for code blocksCopy
1
2
3
4
5
//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:

Use dark colors for code blocksCopy
1
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

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{
  "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.
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{
  "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
                ]
              ]
            ]
          }
        }
      ]
    }
  ]
}

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