I have a feature class of highway ramps and a related table that houses the unique field to create the relate and a couple other fields I am trying to automatically populate on save
Can I configure field maps to Automatically create a new Related record on SAVE of the original record writing to a related table. Thus creating a historical table of change over time..
Example:
1. Ramp Status field on the Line Feature Class is OPEN
2. User clicks on the record and updates the status to CLOSED
3. I want to have a record created in the related table that pulls info from the Main Feature.
ex. The STATUS, USER, RAMPID, TIMESTAMP
Where the user does NOT have to do anything but change the STATUS on the main feature and the related record is created automatically.
This would only create a new Record if and when the STATUS field was changed.
Hi @kapalczynski,
You can definitely do this in Field Maps. You would simply need to configure the Field Calculation with a script similar to the one below.
var FiltValue = $feature.RAMPID
var Status = $feature.STATUS
var OrigStatus = $originalfeature.STATUS
var UpdteTble = FeatureSetByName($map,'<Name of table/featureclass>',['<fieldnames>'],False)
UpdteTble = Filter(UpdteTble,'RAMPID = @FiltValue')
/*
var Values = Dictionary('STATUS', $feature.STATUS, fieldB, ValueB, ... )
*/
var Defaults = { result: { attributes: {'STATUS': $feature.STATUS } } }
var Edits = []
if( OrigStatus == 'OPEN' && Status == 'CLOSED' && Count(UpdteTble)==0 ){
var Changes = Dictionary('className','<TblName>')
var TblDict = Dictionary() // Can use the same values in the values dictionary if the field names are the same
Changes['adds'] = Dictionary('attributes',TblDict)
Push( Edits, Changes )
}
if( Count( Edits ) > 0 ){ Defaults['edit'] = Edits }
return Defaults
First off thank you..... very appreciated.
Hi @kapalczynski,
You can look up the documentation ArcGIS Arcade in addition to Advanced Editing to help you get a better understanding of what the script is doing.
Here are my answers to your questsions:
var E = {
'edits':[{
'className':'<featureclassname>',
'updates':[{
'OBJECTID': $feature.RelObjID,
'attributes': Dictionary('RelFldA','Value','RelFldB','...')//If fields match then use the same as the original
}]
}]
}
The script above is more of a general example but you can configure it to work however you like. Just make sure that the formatting is done correctly or the variables, fields, etc are the correct ones.
If you need to the get the object id of the related record then change the script above to look like the one below.
var FiltValue = $feature.RAMPID
var Status = $feature.STATUS
var OrigStatus = $originalfeature.STATUS
var UpdteTble = FeatureSetByName($map,'<Name of table/featureclass>',['<fieldnames>'],False)
UpdteTble = Filter(UpdteTble,'RAMPID = @FiltValue')
/*
var Values = Dictionary('STATUS', $feature.STATUS, fieldB, ValueB, ... )
*/
var Defaults = { result: { attributes: {'STATUS': $feature.STATUS } } }
var Edits = []
if( OrigStatus == 'OPEN' && Status == 'CLOSED' ){
var Changes = Dictionary('className','<TblName>')
var TblDict = Dictionary() // Can use the same values in the values dictionary if the field names are the same
if( Count(UpdteTble)==0 ){
Changes['adds'] = Dictionary('attributes',TblDict)
}
else if( Count(UpdteTble)==1 ){
var OID = First(UpdteTble).OBJECTID
Changes['updates'] = Dictionary('OBJECTID',OID,'attributes',TblDict)
}
Push( Edits, Changes )
}
if( Count( Edits ) > 0 ){ Defaults['edit'] = Edits }
return Defaults