AnsweredAssumed Answered

Spatial query for attribute and apply to feature before apply edits

Question asked by krishnavsav on Jan 1, 2017
Latest reply on Jan 9, 2017 by krishnavsav

Hello All,


I'm using Web App Builder 2.2 Developer Edition.


Once feature is captured using Edit Widget, I want to apply attributes from the spatial query before apply edits. I have written my code as below to achieve this but query gets completed after attribute inspector is opened.


_canDeleteSelectionFeatures: function () {
// return ture if all features can be deleted,
// else return false.
var canDeleteFeatures = true;
var selectionFeatures = this._getSelectionFeatuers();
if(selectionFeatures.length === 0) {
canDeleteFeatures = false;
} else {
array.some(selectionFeatures, function (feature) {

var featureLayer = feature.getLayer && feature.getLayer();


//I have written below line 
on(featureLayer, 'before-apply-edits', lang.hitch(this, this.onBeforeApplyEdits))

if (!featureLayer ||
!featureLayer.getEditCapabilities({ feature: feature }).canDelete
) {
canDeleteFeatures = false;
return true;

}, this);
return canDeleteFeatures;


and then onBeforeApplyEdits, I have done spatial query to get the required attribute as below:


onBeforeApplyEdits: function (evt) {

if (evt.adds != null) {


var selectionFeatures = this._getSelectionFeatuers();

array.some(selectionFeatures, lang.hitch(this,function (feature) {

var queryDivsionName = new Query();
queryDivsionName.returnGeometry = false;
queryDivsionName.outFields = ["division"];
queryDivsionName.geometry = feature.geometry;
queryDivsionName.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;

var queryDivsionNameTask = new QueryTask(divsionLayer.url);

execute(queryDivsionName, lang.hitch(this, function (featureSet) {
divisionName = featureSet.features[0].attributes.division;


evt.adds[0].attributes.division = divisionName ;


Please suggest how to spatial query for attribute and apply to feature before apply edits.