Autopopulate field with Query in Edit widget

08-31-2016 08:41 AM
Occasional Contributor

Curious if anyone's had any success with this. Here's the scenario:

I have an app built with edit abilities. The user is placing points within parcels and one of the editable fields in the points feature is the Parcel PIN number. Currently they're clicking the parcel, copying the PIN, opening the Edit widget, placing a dot within the parcel, then pasting the PIN number into the field. I'm sure there's a way to run a Query in the background that fires on the click that creates the point and can autopopulate the PIN field, but it's beyond me.

Anyone have any suggestions?

Tags (3)
0 Kudos
1 Reply
Occasional Contributor

This is as far as I've gotten in terms of trying to get the Query into the Edit widget. I'm not sure whether I need to include a QueryTask, a FeatureSet, an AttributeInspector or a RelationshipQuery as well. 

_worksAfterCreate: function(settings) {
// add close button to atiInspector
// resize editPopup
this.editPopup.resize(500, 251);
// update templatePicker for responsive.
//Add the layer for the query to run against

//Add the query. Might not need
// this.pinQuery = new Query ({
// spatialRelationship: Query.SPATIAL_REL_WITHIN,
// outFields: ["PIN"]
// });

//Execute the query. Used to symbolize it's when the map is clicked
this.editor.templatePicker.on("selection-change", lang.hitch(this, function() {
var selected = this.editor.templatePicker.getSelected();
if (selected) {
var featureLayer = selected.featureLayer;

on.once(featureLayer, "before-apply-edits", lang.hitch(this, function(evt){
var pinLayer = new FeatureLayer ("REST URL FOR PARCELS", {
id: "pinLayer",
mode: FeatureLayer.MODE_SELECTION,
outFields: ["*"]
var pinQuery = new Query();
//var pinQueryTask = new QueryTask("REST URL FOR PARCELS");
pinQuery.geometry = evt.mapPoint;
pinQuery.outFields = ["PIN"];
pinQuery.spatialRelationship = Query.SPATIAL_REL_WITHIN;
pinLayer.selectFeatures(pinQuery, FeatureLayer.SELECTION_NEW, function(features){

if(evt.adds && evt.adds.length > 0){
evt.adds[0].attributes.PIN = ["PIN"]; //PIN = 'PIN'; returns PIN in field

//just for BoxTheme
setTimeout(lang.hitch(this, this._update), 900);



0 Kudos