Select to view content in your preferred language

Create and Populate Related Record from Main Record on SAVE

82
3
Tuesday
kapalczynski
Frequent Contributor

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.

0 Kudos
3 Replies
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

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
0 Kudos
kapalczynski
Frequent Contributor

First off thank you..... very appreciated.

  1. Would this calculate run after the save button or submit button to capture the new status that was selected?
  2. What if I have 5 or 6 status values... how would that effect the script... 
  3. If I define the VALUES variable with multiple fields does that replace the DEFAULTS variable

    I can read this but confused on the workflow and how this is actually creating the record in the related table
0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

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:

  1. The script above will trigger every time some hits submit and so long as whatever conditions are met.
  2. If you have multiple status types but you simply want to update the related record, then you would only need to have it to that if the record already exists then it will simply get updated. Updates in arcade look like the code below.
var E = { 
	'edits':[{ 
		'className':'<featureclassname>',
		'updates':[{
			'OBJECTID': $feature.RelObjID,
			'attributes': Dictionary('RelFldA','Value','RelFldB','...')//If fields match then use the same as the original
			}]
		}]
	}
  • Yes. The key is that the fields in one record must be mapped accordingly, otherwise the edits will not apply. I use Defaults as an example variable. You can replace it with anything that works for you.

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

 

0 Kudos