Query Related Records (Feature Service)

Description

The Query operation is performed on a feature service layer resource. The result of this operation are 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.

All parameters related to geometry are ignored when querying related tables.

You can provide arguments to the Query Related Records operation as query parameters defined in the following parameters table:

Request parameters

Parameter

Details

f

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

Values: html | json | amf

objectIds

Description: The object IDs of the layer/table to be queried. Records related to these object IDs will be queried.

Syntax: objectIds=<objectId1>, <objectId2>

Example: objectIds=37, 462

relationshipId

Description: The ID of the relationship to be queried. The relationships that this layer/table participates in are included in the Feature Service Layer resource response. Records in tables/layers corresponding to the related table/layer of the relationship are queried.

Example: relationshipId=4

outFields

Description: The list of fields from the related table/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

Example (wildcard usage): outFields=*

definitionExpression

Description: The definition expression to be applied to the related table/layer. From the list of objectIds, only those records that conform to this expression are queried for related records.

Example: definitionExpression=POP2000 > 100000

returnGeometry

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

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

If the outFields parameter is set to the wildcard "*", it implicitly implies that returnGeometry=true and setting returnGeometry to false has no effect.

Values: true | false

maxAllowableOffset

This option was added at 10.1.

Description: This option can be used to specify the maxAllowableOffset to be used for generalizing geometries returned by the query operation.

The maxAllowableOffset is in the units of the outSR. If outSR is not specified, then maxAllowableOffset is assumed to be in the unit of the spatial reference of the map.

Example: maxAllowableOffset=2

geometryPrecision

This option was added at 10.1.

Description: This option can be used to specify the number of decimal places in the response geometries returned by the query operation.

This applies to X and Y values only (not m or z-values).

Example: geometryPrecision=3

outSR

Description: The spatial reference of the returned geometry.

The spatial reference can be specified as either 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.

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

gdbVersion

This option was added at 10.1.

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

If this is not specified, query will apply to the published map’s version.

Syntax: gdbVersion=<version>

Example: gdbVersion=SDE.DEFAULT

returnZ

This option was added at 10.1.

Description: If true, Z values are included in the results if the features have Z values. Otherwise, Z values are not returned. The default is false.

This parameter only applies if returnGeometry is true.

returnM

This option was added at 10.1.

Description: If true, M values are included in the results if the features have M values. Otherwise, M values are not returned. The default is false.

This parameter only applies if returnGeometry is true.

Example usage

Example 1: Query related records defined by relationship id 2 that are related to OBJECTIDs 3, 4, and 5 in layer 0.

http://myserver/ArcGIS/rest/services/Petroleum/KSPetro/FeatureServer/0/queryRelatedRecords?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

{
  "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
                ]
              ]
            ]
          }
        }
      ]
    }
  ]
}