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