Select to view content in your preferred language

Populate Current Date into Field in Smart Editor Widget

2283
5
10-12-2018 12:05 PM
CarverCounty
New Contributor II

Hello all,

I am looking to auto populate a date field with the current date whenever I add a new feature using the Smart Editor widget.   I am aware of the tracking fields but I need to follow a specific field schema and populate a specific field.  I have tried using preset values in the Smart Editor app but cannot figure out how to set it up to handle using the current date.

I am using WAB Dev 2.9.

Thanks in advance,

Craig

0 Kudos
5 Replies
CarverCounty
New Contributor II

I found this link for the Edit widget but couldn't get the logic written correctly for the Smart Editor.

https://community.esri.com/thread/170004 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Craig,

  I have not tested this at all but this should work. Make these changes to the widget.js _postChanges function:

      // posts the currentFeature's changes
      _postChanges: function (feature) {

        var deferred = new Deferred();

        var result = this._changed_feature(feature, false);
        var returnFeature = result[0];
        var layerId = result[1];
        var type = result[2];
        var layer = null;
        var postDef = null;
        if (returnFeature === null) {
          deferred.resolve("success");
        }
        else if (type === "Add") {
          if (this._traversal.length > 1) {
            this.addNewRelatedRecord = true;
          }
          //Get layer or table info as now user can update related records/features
          layer = this._jimuLayerInfos.getLayerOrTableInfoById(layerId).layerObject;
//Add the autopopulate field value
          if(returnFeature.attributes.hasOwnProperty('Begin_Date_Occ')){  
            returnFeature.attributes.Begin_Date_Occ = new Date(Date.now());  
          }  
          this.attributeInspector.refresh();
//End Add
          postDef = layer.applyEdits([returnFeature], null, null);
          this.addDeferred(postDef, returnFeature, layer, deferred);
        }
...
CraigPrisland2
New Contributor III

Thanks again with the assistance Robert.  I really appreciate it.  After I used your custom code, I added a new point and I am looking for the "Update Date" to auto populate with the current date, is this possible?  It remains empty.

 

However, after I saved this new point, in the Dev console I get the following error saying that this.attributeInspector is undefined.

Again, thanks for all you do!

Craig

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Craig,

   Change that line to:

this.attrInspector.refresh();
0 Kudos
CraigPrisland2
New Contributor III

Hi Robert,

Thanks for the reply.  However, after updating this line, I am now getting the following error when trying to save this new point.  I did ensure that the field ("UPDATEDATE") that I am trying to auto populate is a Date field.  Also, my web console is not returning any errors as well?

Thanks,

Craig

0 Kudos