With a feature service that has a related table, is there a way to set a definition expression using the fields in the related table? For example, with the feature service located at https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0, is it possible to create a definition expression that would only show me Incidents that had an Incident Priority record more recent than a certain date?
[GIS] Filtering an ArcGIS Feature Service by Related Table
arcgis-javascript-apifeature-service
Related Solutions
Use esri.request() to hit each layer's REST endpoint to get info about fields. Here's a simple example:
<html>
<head>
<script type="text/javascript">var djConfig = {parseOnLoad: true};</script>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.4"></script>
<script type="text/javascript">
dojo.require("esri.map");
// var service_url = 'http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hurricanes/NOAA_Tracks_1851_2007/MapServer/layers';
var service_url = 'http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Fire/Sheep/MapServer/layers';
function init() {
esri.request({
url: service_url,
content: { f: 'json' },
callbackParamName: 'callback',
load: processServiceInfo,
error: errorHandler
});
}
// Runs once
function processServiceInfo(info) {
console.log('svc info: ', info);
dojo.byId('info').innerHTML = '';
dojo.forEach(info.layers, function(lyr) {
// Add a new div for each Layer
var lyr_div = dojo.create('div', {
id: 'layer_' + lyr.id,
innerHTML: '<strong>Layer: ' + lyr.name + '</strong><br />'
}, dojo.byId('info'));
dojo.forEach(lyr.fields, function(field) {
lyr_div.innerHTML += 'Name: ' + field.name + '; Alias: ' + field.alias + '<br />';
});
});
}
function errorHandler(err) {
console.log('error: ', err);
}
dojo.ready(init);
</script>
</head>
<body>
<div id="info">field names and aliases will show up here.</div>
</body>
</html>
That code uses v2.0 of the API but the same thing will work at 2.3 or 2.4. I originally posted in the Esri JS API forum.
Edit: Updated to handle all layers in a service. The code also now uses version 2.4 of the API.
If you wanna to get only 1 record try use TOP
statement.
ie:
OBJECTID IN (SELECT TOP 1 OBJECTID FROM 'customers' ORDER BY OBJECTID))
but you have note that this is bypass because TOP
and LIMIT
arent supported by geodatabase http://forums.arcgis.com/threads/68997-TOP-100
EDIT I digged deeper cause this subject seems to me as interesting, and I found this kind of script: http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=E780BB87-1422-2418-7FD8-A1A0D8167AAF it returns a subset of features with the same schema as oryginal. It's made in python so, maybe you could use it as geoprocessing service as gate to your sql queries.
EDIT2
From more research i think that using TOP
LIMIT
or ROWNUM
depends on your DB engine. But the main clue is to use it as subquery - because we only can get access from WHERE
part of statement by using API
NOTE FOR 10.2 USERS: This will not work because it defaults to standardized queries which don't allow subqueries. You can turn off standardized queries, but this is not recommended since it makes SQL injection attacks easier to perform.
Best Answer
if you snoop the network traffic in this sample, you'll see that additional queries for the attributes of related records aren't made until an individual feature has been clicked. this is because only the attributes present in the feature service itself are available automatically for filtering.
as an alternative, you could: