English

Problem: Unable to return updated records to a query from a feature layer in a web map

Description

In certain cases, when a feature is updated in a web map, the updated records are not returned when the web browser is refreshed or auto-refreshes using the refreshInterval function in ArcGIS API for JavaScript.

The following code sample demonstrates a query that fails to return the updated query response:

var featureLayer = new FeatureLayer(featureLayerUrl, {
            mode: FeatureLayer.MODE_ONDEMAND,
			refreshInterval: 0.25,
            visible: true,
            outFields: ["*"],
            id: "fLayer"
});
Note:
The above code sample refreshes the query every 0.25 minutes, or 15 seconds. The refreshInterval function refreshes the query by the number of  minute(s) specified. For more information, refer to the following web help document: ArcGIS API for JavaScript: Class: Layer.

Cause

The updated records in the specified feature layer refresh interval are not returned from the service because the service is returning cached data to the query requests. There may be limited space for caching set in the web browser, which results in the edits not being registered, and hence the updates to a query are not returned.

Solution or Workaround

Implement the esriRequest.setRequestPreCallback() function before running the query request and pass a unique timestamp to the query request. The function returns a new response instead of a cached response, and ignores the cache limitations on the browser. The code snippet below shows esriRequest.setRequestPreCallback() receives an input from a preset function, addTimeStamp() that uses time and date from the refresh interval. For more information, refer to the following web help document: ArcGIS API for JavaScript: Function: esri/request.

esriRequest.setRequestPreCallback(addTimeStamp);

function addTimeStamp(ioArgs) {
	if(ioArgs.url == (featureLayerUrl + "/query")) {
		ioArgs.content = ioArgs.content || {};
		ioArgs.content.timeStamp = new Date().getTime();
	}
	return ioArgs;
}

Related Information