AnsweredAssumed Answered

esriRequest  calling a Asp.net Rest web service

Question asked by jsn on Dec 7, 2016
Latest reply on Dec 8, 2016 by rscheitlin

Hello everyone,

 

I was able to call an asp.net vb.net Rest web service using this sample as template

https://developers.arcgis.com/javascript/3/jssamples/data_requestJson.html

and it works fine.

Now when I copy/paste the same code into the edit widget (Widget.js) code, it jumps from line:

var requestHandle = esriRequest

to line

this.editor.attributeInspector.refresh();

and it never executes this code: requestHandle.then(

I know that esriRequest is asynchronous, but I do not know how to change the code here to handle the return in the widget.

Here is the source code:

_worksAfterCreate: function (settings) {

           ...

          ...

       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) {

                          if (evt.adds && evt.adds.length > 0) {

                              //

                              // Query WasdIndex Layer for Atlas and TTRRSS

                              //

                              this.query = new Query();

                              var countOfFeatures = 0;

                              var polygon = evt.adds[0].geometry;

                            var centroid = polygon.getCentroid();

                              this.query.geometry = polygon;

                              this.query.returnGeometry = true;

                              this.query.outFields = ['*'];

                              this.query.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;

                              this.queryTask.execute(this.query, function (results) {

                                  //

                                  // Populate ATLAS field

                                  //

                                  if (results.features && results.features.length > 0) {

                                      dojo.forEach(results.features, function (feature) {

                                          countOfFeatures++;

                                          evt.adds[0].attributes.ATLAS = feature.attributes.ATLAS; }

                                    )};

 

                                  alert("Number of points in polygon " + countOfFeatures);

                                }, function (showErr) {

                                  console.log('error in query execution');

                              });

                              //

                              // Populate Comment for testing purposes

                            //

                              if (evt.adds[0].attributes.hasOwnProperty('COMMENTS')) {

                                  evt.adds[0].attributes.COMMENTS = 'TEST COMMENTS';

                              }

                            //

                              // Populate AASISID

                             //

                              if (evt.adds[0].attributes.hasOwnProperty('AASISID')) {

                                  esriConfig.defaults.io.proxyUrl = "/proxy/";

                                  var url = "http://localhost:59297/api/aasis";

                                  var requestHandle = esriRequest({

                                      "url": url,

                                      "handleAs": "json",

                                      "callbackParamName": "jsoncallback"

                                  });

                                

                                 requestHandle.then(                        <<<<=== THIS IS WHERE I HAVE THE PROBLEM

                                    function (response) {

                                      console.log("Success: ", response);

                                    },

                                    function (error) {

                                        console.log("Error: ", error.message);

                                 });

                              }

                            this.editor.attributeInspector.refresh();

                          }

                      }));

                  }

              }));

Outcomes