Update a field

3917
2
02-05-2015 06:42 AM
MiriEshel
New Contributor III

Hi everyone,

I'm trying to automatically update a date field with Date.now() value using the Edit widget with some changes.

What ever I do, it does not update the field.

Can someone tell me what's wrong with my code?

this.editor = new Editor(params, this.editDiv);
this.editor.startup();
var feature;
      
var attInspector = this.editor.attributeInspector; 
attInspector.showObjectID = false;
      
var theMap = this.editor.settings.map;
var saveButton = new dijit.form.Button({label:"שלח","class":"saveButton"}); 
dojo.place(saveButton.domNode, attInspector.deleteBtn.domNode, "before"); 

saveButton.on("click", function(evt) {
  if (feature == null)
   alert("Pleae enter values");
  else {
   if (feature.attributes["description"] == null) {
      alert("Description field is required");
      return;
   }
  
  feature.attributes["date1"] = Date.now();      
   theMap.infoWindow.hide();
  }
});

attInspector.on("attribute-change", function(evt) {
   feature = evt.feature;
   feature.attributes["date1"] = Date.now();
   feature.getLayer().applyEdits(null, [feature], null);
});

theMap.infoWindow.resize(350, 600);
        this.resize();
      },

Thanks a lot,

Miri

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Miri,

  Try this:

var currentDate = new Date();
var currentDate = Date.UTC(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate(), currentDate.getUTCHours(), currentDate.getUTCMinutes(), currentDate.getUTCSeconds(), 0);

attInspector.on("attribute-change", function(evt) {
   feature = evt.feature;
   feature.attributes["date1"] = currentDate;
   feature.getLayer().applyEdits(null, [feature], null);
});

Reference thread: Re: Hard-code Attribute Values for Fields with AttributeInspector?

0 Kudos
MiriEshel
New Contributor III

Hi Robert,

Unfortunately it didn't help.

I think you ment to define two different variables, isn't it? something like:

var currentDate = new Date(); 

var currentDate1 = Date.UTC(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate(), currentDate.getUTCHours(), currentDate.getUTCMinutes(), currentDate.getUTCSeconds(), 0); 

 

attInspector.on("attribute-change", function(evt) { 

   feature = evt.feature; 

   feature.attributes["date1"] = currentDate1

   feature.getLayer().applyEdits(null, [feature], null); 

}); 

But anyway, both of them don't work.

I think it's more timimg Issue rather than the Date format. Only once, during Debug, I saw the date entered but I cannot reproduce it any more.

it's also related to the Editor or AttributeInspector classes in Javascript API rather than the Web AppBuilder.

Thanks a lot,

Miri

0 Kudos