Sharing some functions that could be added for further arcade enhancements

220
2
01-14-2025 09:59 AM
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

The functions below work for ArcGIS Enterprise 10.8 and later. I have used these two functions quite often since these automatically account for matching field names but don't account for field types.

// Get matching field names found in both lists
function GetMatchingFields( FieldListA, FieldListB ){
var MatchingFields = Null
var separator = ','
// Loop through the list of field names in list A
for ( var a in FieldListA ){
for ( var b in FieldListB ){
if ( FieldListA[ a ] == FieldListB[ b ] ){ MatchingFields += FieldListA[ a ] + separator }
}
}
if ( IsEmpty( MatchingFields ) == False ){ MatchingFields = split( MatchingFields , separator ) }
return MatchingFields
}

// Get field names from input features
function GetFieldNames( InputDictionary , OmitFields ){
var FieldNames = Null
var separator = ','
for ( var field in InputDictionary ){
// Populate the specified list with the field name
var keep = True
for ( var i in OmitFields ){
if ( field == OmitFields[ i ] ){ keep = False ; Break }
}
if ( keep == True ){ FieldNames += field + ',' }
}
if ( IsEmpty( FieldNames ) == False ){ FieldNames = split( FieldNames , separator ) }
return FieldNames
}

 

The functions below were updated to use on Enterprise 10.9 and later.

// Get matching field names found in both lists
function GetMatchingFields( FieldListA, FieldListB ){
    var MatchingFields = []
    // Loop through the list of field names in list A
    for ( var a in FieldListA ){
        if ( Includes( FieldListB , a ) ){ Push( MatchingFields , a ) }
        }
    if ( Count( MatchingFields ) == 0 ){ MatchingFields = Null }
    return MatchingFields
    }

// Get field names from input features
function GetFieldNames( InputFeature , OmitFields ){
    if( TypeOf( InputFeature ) == 'Feature' ){ InputFeature = First( InputFeature ) }
    var FieldNames = []
    for ( var field in InputFeature ){
        // Populate the specified list with the field name
        if ( !Includes( OmitFields , field ) ){ Push( FieldNames , field ) }
        }
    if ( Count( FieldNames ) == 0 ){ FieldNames = Null }
    return FieldNames
    }

 

It would be nice if functions like these were added to the library of functions in arcade since it is fairly standard and would be easier to use.

2 Replies
DavidColey
MVP Regular Contributor

Hi @RPGIS - I'm assuming these work with the datastore profile, but otherwise where are you using this?  As an attribute rule? Does this set up a field map for an append or data load op?

0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

I use this as part of an attribute rule for the most part but it I have yet to test it in other places such as dashboards. It's mostly a data load operation, similar to using append with field map.