<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Updating multiple fields using arcade in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/updating-multiple-fields-using-arcade/m-p/1362473#M6871</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure if this is possible or not but I am trying to update a related table from another feature based on changes in the specified date field. Originally I was specifying all of the fields that needed to be inserted. Rather than specifying all of the fields directly; I would like to get all of the attributes based on matching fields.&lt;/P&gt;&lt;P&gt;Here is what I have thus far.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//_______""" Functions for modifying the related table """_________
// Get matching field names
function GetMatchingFields( FieldListA, FieldListB ){
    var MatchingFields = [ ]
    for ( var i in FieldListA ){
        var fieldname = FieldListA[i]
        if ( Includes( FieldListB , fieldname ) ){
            Push( MatchingFields, fieldname )
            }
        }
    return MatchingFields
    }

// Get field names from input features
function GetFieldNames( InputFeature ){
    var FieldNames = [ ]
    var FeatureInfo = Schema(InputFeature).fields
    for ( var i in FeatureInfo ){
        Push( FieldNames , FeatureInfo[ i ].name )
        }
    return FieldNames
    }

//_______""" Specify Variables """_________
var FeatureClassName = 'Insert Featureclass Name'
var TableName = 'Insert Table Name'
var FeatureID = $feature.OBJECTID
var InspDate = $feature.InspectionDate
var IDField = 'OBJECTID'
var DateField = 'InspectionDate'
var Order = DateField + ' DESC'

// Order the features by the date field descending
var History = OrderBy( FeatureSetByName( $datastore, TableName ) , Order )
var Hydrants = $featureset

// Get matching field names found in both features
var MatchingFields = GetMatchingFields( GetFieldNames( Hydrants ), GetFieldNames( History ) )

// If the date has a count greater than 1 then populate the list with unique dates
var DateCount = Count( Filter( Hydrants, DateField + ' = @InspDate' ) )
while ( DateCount != 0 ){
    var DateChange = DateAdd( InspDate , DateCount, 'seconds')
    var DateCheck = Count( Filter( Hydrants, DateField + ' = @DateChange' ) )
    if ( DateCheck == 0 ){
        var InspDate = DateChange
        break
        }
    else { var DateCheck = DateCheck - 1 }
    }
return InspDate

// Filter feature by criteria
var FilteredFeature = First( Filter( History, DateField + ' = @InspDate' ) )

// Insert records into the related table if the date does not exist in the related table
var Values = First( Filter( FeatureSetByName($datastore, FeatureClassName , MatchingFields ), DateField + ' = @InspDate' ) )
if ( InspDate &amp;gt; First( History )[ DateField ] ){
    Console( 'Inserting record from @FeatureClassName into @TableName' )
    return {
         "result": InspDate,
         "edit": [ {  
             // Specify the related table
             "className" : TableName, 
             //the type of edit, in this case we want to add so we say `adds`, its an array since we can make many inserts
             "adds" : [ {
                 // Add the current feature data based on the object id of the filtered data
                 "attributes": Values
                 } ]
            } ]
        }
    }
else if ( InspDate == FilteredFeature[ DateField ] ) {
    Console( 'Updating record from @FeatureClassName into @TableName' )
    return {
         "result": InspDate,
         "edit": [ {  
             // Specify the related table
             "className" : Table, 
             //the type of edit, in this case we want to add so we say `adds`, its an array since we can make many inserts
             "updates" : [ {
                 // Specify the object id of the feature
                 IDField : FilteredFeature[ IDField ],
                 // Add the current feature data based on the object id of the filtered data
                 "attributes": Values
                 } ]
            } ]
        }
    }    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure if I correctly wrote this script to do just that or if there is a simpler solution that already exists. Any help would be greatly appreciated.&lt;/P&gt;</description>
    <pubDate>Tue, 19 Dec 2023 13:02:42 GMT</pubDate>
    <dc:creator>RPGIS</dc:creator>
    <dc:date>2023-12-19T13:02:42Z</dc:date>
    <item>
      <title>Updating multiple fields using arcade</title>
      <link>https://community.esri.com/t5/developers-questions/updating-multiple-fields-using-arcade/m-p/1362473#M6871</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure if this is possible or not but I am trying to update a related table from another feature based on changes in the specified date field. Originally I was specifying all of the fields that needed to be inserted. Rather than specifying all of the fields directly; I would like to get all of the attributes based on matching fields.&lt;/P&gt;&lt;P&gt;Here is what I have thus far.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//_______""" Functions for modifying the related table """_________
// Get matching field names
function GetMatchingFields( FieldListA, FieldListB ){
    var MatchingFields = [ ]
    for ( var i in FieldListA ){
        var fieldname = FieldListA[i]
        if ( Includes( FieldListB , fieldname ) ){
            Push( MatchingFields, fieldname )
            }
        }
    return MatchingFields
    }

// Get field names from input features
function GetFieldNames( InputFeature ){
    var FieldNames = [ ]
    var FeatureInfo = Schema(InputFeature).fields
    for ( var i in FeatureInfo ){
        Push( FieldNames , FeatureInfo[ i ].name )
        }
    return FieldNames
    }

//_______""" Specify Variables """_________
var FeatureClassName = 'Insert Featureclass Name'
var TableName = 'Insert Table Name'
var FeatureID = $feature.OBJECTID
var InspDate = $feature.InspectionDate
var IDField = 'OBJECTID'
var DateField = 'InspectionDate'
var Order = DateField + ' DESC'

// Order the features by the date field descending
var History = OrderBy( FeatureSetByName( $datastore, TableName ) , Order )
var Hydrants = $featureset

// Get matching field names found in both features
var MatchingFields = GetMatchingFields( GetFieldNames( Hydrants ), GetFieldNames( History ) )

// If the date has a count greater than 1 then populate the list with unique dates
var DateCount = Count( Filter( Hydrants, DateField + ' = @InspDate' ) )
while ( DateCount != 0 ){
    var DateChange = DateAdd( InspDate , DateCount, 'seconds')
    var DateCheck = Count( Filter( Hydrants, DateField + ' = @DateChange' ) )
    if ( DateCheck == 0 ){
        var InspDate = DateChange
        break
        }
    else { var DateCheck = DateCheck - 1 }
    }
return InspDate

// Filter feature by criteria
var FilteredFeature = First( Filter( History, DateField + ' = @InspDate' ) )

// Insert records into the related table if the date does not exist in the related table
var Values = First( Filter( FeatureSetByName($datastore, FeatureClassName , MatchingFields ), DateField + ' = @InspDate' ) )
if ( InspDate &amp;gt; First( History )[ DateField ] ){
    Console( 'Inserting record from @FeatureClassName into @TableName' )
    return {
         "result": InspDate,
         "edit": [ {  
             // Specify the related table
             "className" : TableName, 
             //the type of edit, in this case we want to add so we say `adds`, its an array since we can make many inserts
             "adds" : [ {
                 // Add the current feature data based on the object id of the filtered data
                 "attributes": Values
                 } ]
            } ]
        }
    }
else if ( InspDate == FilteredFeature[ DateField ] ) {
    Console( 'Updating record from @FeatureClassName into @TableName' )
    return {
         "result": InspDate,
         "edit": [ {  
             // Specify the related table
             "className" : Table, 
             //the type of edit, in this case we want to add so we say `adds`, its an array since we can make many inserts
             "updates" : [ {
                 // Specify the object id of the feature
                 IDField : FilteredFeature[ IDField ],
                 // Add the current feature data based on the object id of the filtered data
                 "attributes": Values
                 } ]
            } ]
        }
    }    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure if I correctly wrote this script to do just that or if there is a simpler solution that already exists. Any help would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 13:02:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/updating-multiple-fields-using-arcade/m-p/1362473#M6871</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2023-12-19T13:02:42Z</dc:date>
    </item>
  </channel>
</rss>

