<?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 Re: Arcade expression to insert a record into a related table? in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/arcade-expression-to-insert-a-record-into-a/m-p/1570712#M7373</link>
    <description>&lt;P&gt;Curious to hear about your solution. Do you have any documentation?&lt;/P&gt;</description>
    <pubDate>Fri, 20 Dec 2024 19:36:12 GMT</pubDate>
    <dc:creator>MatthewTrabun</dc:creator>
    <dc:date>2024-12-20T19:36:12Z</dc:date>
    <item>
      <title>Arcade expression to insert a record into a related table?</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-expression-to-insert-a-record-into-a/m-p/1331051#M6750</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have been trying to figure out how to create an attribute rule to add a record in a related table based on certain criteria. I am not sure, since I am still learning quite a bit about arcade, how to go about it. I typically program in python, but I am trying to reduce the scripting that would be needed outside of a database when a simple attribute rule could accomplish a similar task.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Function for defining whether or not a fieldname exists in another feature
function ValidateFieldNames( InputFieldsA, InputFieldsB ){
    var AFields = [ ]
    var BFields = [ ]
    for ( var i = 'name' in InputFieldsA ){
        return Push( AFields, InputFieldsA[ i ] )
    }
    for ( var i = 'name' in InputFieldsB ){
        return Push( BFields, InputFieldsB[ i ] )
    }
    for ( var Fieldname in BFields ){
        var FieldnameIndex = IndexOf( AFields, InputFieldsB[ Fieldname ] )
        if ( Includes( AFields, InputFieldsB[ Fieldname ] ) == False ){
            return Erase( AFields, FieldnameIndex )
        }
    }
}

// Current date
var CurrentYear = Year( Date( Now() ) )
// Inspection year and date
var InspectedYear = $feature.FieldYear
var InspectedDate = $feature.FieldDate
// Inspection record table
var InspectionRecords = FeatureSetByName( $datastore, "Featureclass", ['*'] )
Console( InspectionRecords )
// Get array of recorded inspection year and get only unique years in descending order
var RecordedDates = FeatureSetByName( $datastore, "Table", ['InspectionDate'] )
var RecordedYears = Max( Year( RecordedDates ) )

// Get the matching fieldnames that exist in both features
var InspectionRecordSchema = Schema( InspectionRecords ).fields
var MatchingFieldnames = ValidateFieldNames( InspectionRecords, $feature )

// Loop through the update items to create a concatenated text value of items
// to create a single text line of dictionary values
var UpdateItems = NULL
for ( var field in MatchingFieldnames ){
    var ConcatText = Concatenate( field, ' : ', $feature[ field ] )
    iif ( UpdateItems == NUll, UpdateItems == ConcatText, Concatenate( UpdateItems, ',', ConcatText ) )
    }
var UpdateItems = Dictionary( UpdateItems )

// If the current inspection year in the inspected hydrant layer
// is not in the inspection records table. Then add the record to
// the inspection table
if ( CurrentYear == InspectedYear &amp;amp;&amp;amp; InspectedYear &amp;gt;= RecordedYears ){
    return {
         'result' : InspectedDate,
         'edit': [
           {
               'classname' : "Featureclass",
               'adds' : [
                   {
                   'objectID': $feature.ObjectID,
                   'attributes' :  UpdateItems
                   }
                ]
            }
        ]
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help with this would be greatly appreciated?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 19:28:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-expression-to-insert-a-record-into-a/m-p/1331051#M6750</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2023-09-27T19:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression to insert a record into a related table?</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-expression-to-insert-a-record-into-a/m-p/1333077#M6770</link>
      <description>&lt;P&gt;Never mind. I finally figured out a solution which works really well.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 19:43:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-expression-to-insert-a-record-into-a/m-p/1333077#M6770</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2023-09-27T19:43:54Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression to insert a record into a related table?</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-expression-to-insert-a-record-into-a/m-p/1570712#M7373</link>
      <description>&lt;P&gt;Curious to hear about your solution. Do you have any documentation?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2024 19:36:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-expression-to-insert-a-record-into-a/m-p/1570712#M7373</guid>
      <dc:creator>MatthewTrabun</dc:creator>
      <dc:date>2024-12-20T19:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression to insert a record into a related table?</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-expression-to-insert-a-record-into-a/m-p/1570789#M7374</link>
      <description>&lt;P&gt;Hi @MatthewTrabu,&lt;/P&gt;&lt;P&gt;I have documentation but I'm need to upload the updated version. I plan on restructuring my code eventually since I've gotten more efficient with the new language.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2024 00:27:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-expression-to-insert-a-record-into-a/m-p/1570789#M7374</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2024-12-21T00:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression to insert a record into a related table?</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-expression-to-insert-a-record-into-a/m-p/1589587#M7431</link>
      <description>&lt;P&gt;I am trying to accomplish a similar issue. Any documentation would be greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 18:00:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-expression-to-insert-a-record-into-a/m-p/1589587#M7431</guid>
      <dc:creator>AriLukas2</dc:creator>
      <dc:date>2025-02-26T18:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression to insert a record into a related table?</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-expression-to-insert-a-record-into-a/m-p/1589800#M7432</link>
      <description>&lt;P&gt;I have posted a blog of sorts in the Arcade group that shows the updated script.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 22:32:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-expression-to-insert-a-record-into-a/m-p/1589800#M7432</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2025-02-26T22:32:42Z</dc:date>
    </item>
  </channel>
</rss>

