Hi All,
I'm trying to add a field to the Change Log table I've created that tracks edits to our data. The new field would record the changes made to the field values of a feature and would be in dictionary format (field output would be "x field: y new field value, z field: w new field value...). I only want to record fields that have had edits made to them. Here's the code I have so far-- I'm trying to create an empty dictionary, use the Schema tool to get the field names and values, compare them, and push values to the new dictionary that are different from the original values.
var DeviceFeatureEdits = FeatureSetByName($datastore, 'ElectricDevice',['*'], true)
var editscalc = Dictionary()
//schema function returns an array of dictionaries, includes field names
var Cschema = Schema(DeviceFeatureEdits)) //Cschema is the post edit dictionary of field values
var Oschema = Schema(DeviceFeatureEdits.$originalfeature)) //Oschema is the pre-edit dictionary of field values
if (Oschema.assetid != Cschema.assetid){
push (editscalc, Cschema.assetid)
}
//I repeat the above If statement for all the fields.
The lines where I use the Schema function keep causing either "semicolon or new line expected" or "reserved keyword used". Is the schema function not applicable to attribute rules, or am I using it wrong? Is this a viable way to do what I'm trying to do?
Thank you!
Solved! Go to Solution.
Wanted to add that trying this:
var Cschema = Schema($feature)
var Oschema = Schema($originalfeature)
if (Oschema.assetid != Cschema.assetid){
push (editscalc, Cschema.assetid)
}
yields the error message "Field not found assetid"
Hello,
I don't think you can get field values with the Schema function. According to the documentation, this is the result :
fields: Array<Dictionary> - Returns an array of dictionaries describing the fields in the Feature. Each dictionary describes the field name, alias, type, subtype, domain, length, and whether it is editable and nullable.
Field values are not part of the result.
Also in the first line, DeviceFeatureEdits is a featureSet, but Schema function takes a Feature as input, not a featureSet.
To achieve what you want, maybe you can create a function that directly compare $feature fields and values with $originalfeature fields and values and returns a dictionary of edits. I would be interested if you succeed in.