Hard-code Attribute Values for Fields with AttributeInspector?

2254
3
06-13-2012 11:53 AM
AaronDrake
New Contributor
Hi,

I am trying to hard code values for some fields I am accessing in the Attribute Inspector.  Essentially, I would like to set a GIS_Editor and GIS_Edited_Date field(s) equal to the current user (logged in via a asp LoginName).

I am not real sure where this would be done.  I have a section in my code that I tried to do this, but it didn't work.  Am I even looking in the right place?

Here is my test code:

 dojo.connect(attInspector, "onAttributeChange", function (feature, fieldName, newFieldValue) {
        //store the updates to apply when the save button is clicked 
        updateFeature.attributes[fieldName] = newFieldValue;
        updateFeature.attributes["GIS_Editor"] = dojo.byId('LoginName').innerHTML;
        updateFeature.attributes["GIS_Edited_Date"] = dojo.byId('ServerTime').innerHTML;
  });
0 Kudos
3 Replies
HemingZhu
Occasional Contributor III
Hi,

I am trying to hard code values for some fields I am accessing in the Attribute Inspector.  Essentially, I would like to set a GIS_Editor and GIS_Edited_Date field(s) equal to the current user (logged in via a asp LoginName).

I am not real sure where this would be done.  I have a section in my code that I tried to do this, but it didn't work.  Am I even looking in the right place?

Here is my test code:

 dojo.connect(attInspector, "onAttributeChange", function (feature, fieldName, newFieldValue) {
        //store the updates to apply when the save button is clicked 
        updateFeature.attributes[fieldName] = newFieldValue;
        updateFeature.attributes["GIS_Editor"] = dojo.byId('LoginName').innerHTML;
        updateFeature.attributes["GIS_Edited_Date"] = dojo.byId('ServerTime').innerHTML;
  });


I would just do a little change on your onAttributeChange handler. like this:
dojo.connect(attInspector, "onAttributeChange", function (feature, fieldName, newFieldValue) {
        if (fieldName=="GIS_Editor")
        { 
            updateFeature.attributes["GIS_Editor"] = dojo.byId('LoginName').value;
        }
        else if (fieldName == "GIS_Edited_Date")
        { 
           updateFeature.attributes["GIS_Edited_Date"] = dojo.byId('ServerTime').value;
        }
        else
           updateFeature.attributes[fieldName] = newFieldValue;
  });

For add a feature or upate a field where you use statement featureLayer.applyEdits. do the attribute setting as above before you apply the applyEdits.
Hope it works for you.
0 Kudos
AaronDrake
New Contributor
I was able to get it working for the GIS_Editor; however, the GIS_Edited_Date field is not.  I checked to see what the value was for a feature that already had a edited date field, and it came back with a strange number.  I am not sure what date format this is in.

console.log(updateFeature.attributes["GIS_Edited_Date"]);


Results in a number that looks like:
1281499200000

Anybody know what format this is in, and how I can reproduce it with javascript?
0 Kudos
AaronDrake
New Contributor
So it looks like the date is in UTC.  So I used the following code to get it working:

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

This pushes the correct date format back into SDE.

Working code (with hard-coded editor value for now)
dojo.connect(attInspector, "onAttributeChange", function (feature, fieldName, newFieldValue) {
        //store the updates to apply when the save button is clicked 
        updateFeature.attributes[fieldName] = newFieldValue;
        updateFeature.attributes["GIS_Editor"] = 'adrake';
        updateFeature.attributes["GIS_Edited_Date"] = currentDate;
        console.log(updateFeature.attributes["GIS_Editor"]);
        console.log(updateFeature.attributes["GIS_Edited_Date"]);
});
0 Kudos