TL;DR: この式は複数のテーブルにわたる最新の編集概要を返します。<\/P>
var related_records = FeatureSetByRelationshipName($feature, "relationship_name") var sorted_records = OrderBy(related_records, 'last_edited_date DESC') var most_recent_record = First(sorted_records)<\/code><\/pre><P> <\/P><H4 id="toc-hId--1839843622">カスタム関数、関数の結合<\/H4><P>これは各テーブルごとに繰り返される不要な中間出力が多すぎます。可能な限り関数を結合することが望ましいですが、コードが理解しづらくなるほどではありません。<\/P><P>例えば:<\/P><PRE>First(OrderBy(FeatureSetByRelationshipName($feature, "EH_Complaints_violations"), 'last_edited_date DESC'))</PRE><P>これは有効な式ですがかなり長いです。必要なら改行しても構いません。<\/P><PRE>First(<BR \/> OrderBy(<BR \/> FeatureSetByRelationshipName(<BR \/> $feature,<BR \/> "EH_Complaints_violations"),<BR \/> 'last_edited_date DESC')) <\/PRE><P>ただし、この例ではレイヤー内の各関連テーブルごとに多くタイプしなければなりません。個人的にはこういう場合カスタム関数を使うことが好きです。ここではカスタム関数<strong>MostRecent</strong>を使って<strong>First</strong>と<strong>OrderBy</strong>関数を結合します。それから各関連テーブルで使って非常に簡潔に最新フィーチャを取得できます。<\/P><P> <\/P><pre class="lia-code-sample language-javascript"><code>function MostRecent(lyr){ return First(OrderBy(lyr, 'last_edited_date')) } var violations = FeatureSetByRelationshipName($feature, "EH_Complaints_violations") var narrative = FeatureSetByRelationshipName($feature, "EH_Complaints_narrative") var most_recent_v = MostRecent(violations) var most_recent_n = MostRecent(narrative)<\/code><\/pre><P> <\/P><H4 id="toc-hId-647669211">比較<\/H4><P>ここまでは良いですが、これら個別フィーチャから最も最近のフィーチャをどうやって得るのでしょう?これは<strong>OrderBy</strong>は使えません。これらは別々のフィーチャであってFeatureSetではないからです。ただし配列と比較関数を引数に取る<strong>Sort</strong>という関数があります。しかしそれらが不足しています。<\/P><P>配列は簡単です。フィーチャに角括弧とカンマを付ければいいだけです!<\/P><PRE>[most_recent_v, most_recent_n, $feature]<\/PRE><P>比較も簡単です。我々はフィーチャの<strong>last_edited_date</strong>を取ってどちらが大きい(つまりより新しい)かを見るだけです。<\/P><P> <\/P><pre class="lia-code-sample language-javascript"><code>function DateSort(a, b){ if (a['last_edited_date'] > b['last_edited_date']){ return -1 } else { return 1 } } var sorted = Sort([most_recent_v, most_recent_n, $feature], DateSort) var most_recent_feature = First(sorted)<\/code><\/pre><P> <\/P><P>これで最も最近から最も古い順にソートされたフィーチャ配列ができましたので、その配列から<strong>First</strong>値だけ取ればよいわけです。<\/P><P>ただし…どのテーブルから来たかはどうやって分かるのでしょう?<\/P><H4 id="toc-hId--1159785252">遡って元テーブル情報も含める<\/H4><P>式内どこかで個々のフィーチャにテーブル識別子を紐づけなければなりません。一番簡単なのは<strong>dictionay</strong>(辞書)または辞書配列としてフォーマットすることです。以下のようになります:<\/P><P> <\/P><pre class="lia-code-sample language-javascript"><code>[ {table: 'Complaint Details', feat: $feature}, {table: 'Violations', feat: most_recent_v}, {table: 'Narrative', feat: most_recent_n} ]<\/code><\/pre><P> <\/P><P>DateSort関数は同じように動作しますが、今度は大きな辞書内値としてフィーチャへアクセスする必要があります。それはつまり、</P><PRE>a['feat']['last_edited_date']</PRE><P>などとなります。これで単一フィーチャとその元テーブル情報が揃いました。あとは出力文字列を作成するだけです。<\/P><P> <\/P><pre class="lia-code-sample language-javascript"><code>return `${most_recent_feature['table']} layer edited ${most_recent_feature['feat']['last_edited_date']}`
// カスタム関数:最新フィーチャ返す function MostRecent(lyr){ return First(OrderBy(lyr, 'last_edited_date')) } // 各関連テーブル用FeatureSets var violations = FeatureSetByRelationshipName($feature, "EH_Complaints_violations") var narrative = FeatureSetByRelationshipName($feature, "EH_Complaints_narrative") // 元テーブル情報付きフィーチャ辞書配列 var feats = [ {table: 'Complaint Details', feat: $feature}, {table: 'Violations', feat: MostRecent(violations)}, {table: 'Narrative', feat: MostRecent(narrative)} ] // ソート関数 function DateSort(a, b){ if (a['feat']['last_edited_date'] > b['feat']['last_edited_date']){ return -1 } else { return 1 } } var most_recent = First(Sort(feats, DateSort)) // ユーザー名フルネーム取得用追加行 var portal = Portal('https://maps.co.kendall.il.us/portal') var editing_user = GetUser(portal, most_recent['feat']['last_edited_user']) // 最新フィーチャ情報に基づく整形済み出力文字列返却 return `${most_recent['table']} table edited ${Text(most_recent['feat']['last_edited_date'], 'DD-MMM-YYYY')} by ${editing_user}`
On a side note:(I do a similar thing to what @jcarlson mentions above, but I use SQL queries in Oracle, instead of Arcade.)One thing I find frustrating is that domains don't have a date column/property to track the last time the domain was modified.
Scenario — sync to external system:
I have a sidewalk FC that I sync as assets to a work order management system. The sync logic is based on a SYNC_NEEDED column in a spatial view on the FC. That SYNC_NEEDED column is based on the LAST_EDITED_DATE. But ideally, It would also account for changes to domains as well.
For example, the sidewalk FC has a MATERIAL column that uses a MATERIAL_SIDEWALK domain. If someone were to change a value in the domain from, say, CONCRETE to CONCRETE - CAST-IN-PLACE, then ideally, the affected features in the FC should be synced, so that the new material information would show up in the external system.
But since there's no way to query for domains that have changed, that doesn't seem to be possible. The only other option for capturing the domain changes would be to re-sync the entire FC on a schedule, which is problematic since the external system (IBM Maximo) is extremely slow at syncing records. The only realistic option is to sync changes-only, not sync all rows.
Related:
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.