AnsweredAssumed Answered

How to save the result from esriRequest in a field?

Question asked by jsn on Dec 14, 2016
Latest reply on Dec 15, 2016 by jsn

Hello everyone,

 

Is there a way to save any result from esriRequest in a field such as evt.adds[0].attributes.ProjectID ?

 

In the sample below the field   "evt.adds[0].attributes.ProjectID" always takes the value 1000 and never 2000. For testing purposes I am populating it with the value 2000 inside the "requestHandle.then", but even if the program runs the code,  the value in the field "evt.adds[0].attributes.ProjectID"  always shows 1000 not 2000.

 

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

                              //
                              // Populate ProjectID
                              //

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

                                  esriConfig.defaults.io.proxyUrl = this.proxyUrl; // ../proxy/proxy.ashx

                                  var url = this.webServiceUrl;

                                  evt.adds[0].attributes.ProjectID = 1000;   <<= IT ALWYS KEEP THIS VALUE
         
                                  evt.adds[0].attributes.COMMENTS = 'TEST COMMENTS';

                                  var requestHandle = esriRequest({
                                      "url": url,
                                      "handleAs": "json",
                            

                                  }, {
                                      useProxy: true,
                                      usePost: false,
                                      disableIdentityLookup: true
                                  });

                                  //  requestHandle.then(this.requestSucceeded, this.requestFailed);

                                  requestHandle.then(
                                    lang.hitch(this, function (response, io) {

                                        console.log("Data: ", response);
                                        dojoJson.toJsonIndentStr = "  ";
                                        var strProjectID = dojoJson.toJson(response, true);
                                        //
                                        //     evt.adds[0].attributes.ProjectID = parseInt(strProjectID);
                                        //
          
                                        evt.adds[0].attributes.ProjectID = 2000;    <<==== IT NEVER TAKES THIS VALUE 2000.                                                                                                                          WHAT IS MISSING?
                    
                                        console.log("Success: ", response);
                                    }),
                                    lang.hitch(this, function (error, io) {
         
                                        evt.adds[0].attributes.ProjectID = 2000;  <<== IT NEVER TAKES VALUE                2000.  WHAT IS MISSING?

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

                              }

                             this.editor.attributeInspector.refresh();
                          }
                      }));
                  }
              }));

Outcomes