<?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 Filter SLQ in Array Issue in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/arcade-filter-slq-in-array-issue/m-p/1552809#M1614</link>
    <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;I also found that the issue is a few things while troubleshooting.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;1. Y&lt;SPAN data-teams="true"&gt;&lt;SPAN class="ui-provider a b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak"&gt;ou should always use this syntax when you need to inject variables&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;'GlobalID IN @relatedParcelFeatures'&lt;/LI-CODE&gt;
&lt;P&gt;2. I noticed that when using the logic above I get errors with the Replace. If I ignore the replace and just use my array of GlobalIDs I pass validation. Yet get an error on save. Turns out d&lt;SPAN data-teams="true"&gt;&lt;SPAN class="ui-provider a b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak"&gt;uring validation of the expression in the expressions window the code is run on the first object in the $feature. During save there is a "fake" row that is created and run against. So you rule can pass validation because your code is being run against an object that may meet all the code requirements but not save. So you have to do some error handling like checking if the array is empty.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;if (Count(globalIDs)&amp;lt;1){
   return
    }&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN data-teams="true"&gt;&lt;SPAN class="ui-provider a b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak"&gt;&lt;BR /&gt;New code:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;// parcel_Documents Fields
var parcelDocumentsGlobalID_field = "GlobalID"

// parcel Fields
var parcelGlobalID_field = "GlobalID"
var parcelType_field = "type"

var relatedRecords = FeatureSetByRelationshipClass($feature, "parcel_Documents", [parcelDocumentsGlobalID_field], false);
var parcelFeatures = FeatureSetByName($datastore, "parcel", [parcelGlobalID_field ,parcelType_field], false)
var globalIDs = []
for (var record in relatedRecords){
    var rg = record.GlobalID;
    Push(globalIDs, rg);
}

if (Count(globalIDs)&amp;lt;1){
   return
    }

var filteredLandStatusFeatures = Filter(landStatusFeatures, 'GlobalID IN @globalIDs' ) 

var cnt = Count(filteredParcelFeatures)

return {
    "errorMessage": Text(cnt)
}&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN data-teams="true"&gt;&lt;SPAN class="ui-provider a b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 28 Oct 2024 15:07:02 GMT</pubDate>
    <dc:creator>Jake_S</dc:creator>
    <dc:date>2024-10-28T15:07:02Z</dc:date>
    <item>
      <title>Arcade Filter SLQ in Array Issue</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-filter-slq-in-array-issue/m-p/1552745#M1612</link>
      <description>&lt;P&gt;Hey folks,&lt;/P&gt;
&lt;P&gt;Long story long, I have a Many to Many documents table to parcel feature relationshisp. Using the&amp;nbsp;&lt;SPAN&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#featuresetbyrelationshipclass" target="_self"&gt;FeatureSetByRelationshipClass&lt;/A&gt; function to get all the related Parcel GlobalIDs of the $feature (document) being edited and put them into an array. Then use that array to filter all the parcel features to later get some additional information. When I try to use that array in a Filter statement I get "&lt;STRONG&gt;Error: Invalid arcade expression, Arcade error: invalid where clause (GlobalID in ())&lt;/STRONG&gt;".&lt;BR /&gt;&lt;BR /&gt;Any thoughts?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Notes:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Line 17 I have to format the Array to adhere to SLQ. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If you don't you get the following error:&lt;BR /&gt;Invalid where clause (GlobalID IN (["{13C371EB-F80F-4B97-9718-D6CBCF37E8A5}","{4898F30A-5AEC-4BB1-A50C-59ED2FBCAF63}"])). &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The format should look like (grabbed from ArcGIS Pro Select By Attribute SQL:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;GlobalID IN ('{13C371EB-F80F-4B97-9718-D6CBCF37E8A5}', '{4898F30A-5AEC-4BB1-A50C-59ED2FBCAF63}')&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;// parcel_Documents Fields
var parcelDocumentsGlobalID_field = "GlobalID"

// parcel Fields
var parcelGlobalID_field = "GlobalID"
var parcelType_field = "type"

var relatedRecords = FeatureSetByRelationshipClass($feature, "parcel_Documents", [parcelDocumentsGlobalID_field], false);
var parcelFeatures = FeatureSetByName($datastore, "parcel", [parcelGlobalID_field ,parcelType_field], false)
var globalIDs = []
for (var record in relatedRecords){
    var rg = record.GlobalID;
    Push(globalIDs, rg);
}

var relatedParcelFeatures = Replace(Replace(Replace(globalIDs, '"', "'"),"[",""),"]","")

var filteredParcelFeatures = Filter(parcelFeatures, "GlobalID IN (" + relatedParcelFeatures + ")");

var cnt = Count(filteredParcelFeatures)

return {
    "errorMessage": Text(cnt)
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any assistance from the community would be great. Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 13:18:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-filter-slq-in-array-issue/m-p/1552745#M1612</guid>
      <dc:creator>Jake_S</dc:creator>
      <dc:date>2024-10-28T13:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Filter SLQ in Array Issue</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-filter-slq-in-array-issue/m-p/1552769#M1613</link>
      <description>&lt;P&gt;Looking at your code, it seems like the "replace" step is entirely for getting the array-as-string to be formatted differently. Take a look at using &lt;STRONG&gt;Concatenate&lt;/STRONG&gt; instead.&lt;/P&gt;&lt;P&gt;Also try using &lt;STRONG&gt;Console&lt;/STRONG&gt; to check on intermediate outputs.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var globalIDs = []

for (var record in relatedRecords){
  Push(globalIDs, record.GlobalID)
}

var sql = `GlobalID IN('${Concatenate(globalIDs, "','")}')`

Console(sql)

var filteredParcelFeatures = Filter(parcelFeatures, sql)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 13:39:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-filter-slq-in-array-issue/m-p/1552769#M1613</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-10-28T13:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Filter SLQ in Array Issue</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/arcade-filter-slq-in-array-issue/m-p/1552809#M1614</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;I also found that the issue is a few things while troubleshooting.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;1. Y&lt;SPAN data-teams="true"&gt;&lt;SPAN class="ui-provider a b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak"&gt;ou should always use this syntax when you need to inject variables&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;'GlobalID IN @relatedParcelFeatures'&lt;/LI-CODE&gt;
&lt;P&gt;2. I noticed that when using the logic above I get errors with the Replace. If I ignore the replace and just use my array of GlobalIDs I pass validation. Yet get an error on save. Turns out d&lt;SPAN data-teams="true"&gt;&lt;SPAN class="ui-provider a b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak"&gt;uring validation of the expression in the expressions window the code is run on the first object in the $feature. During save there is a "fake" row that is created and run against. So you rule can pass validation because your code is being run against an object that may meet all the code requirements but not save. So you have to do some error handling like checking if the array is empty.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;if (Count(globalIDs)&amp;lt;1){
   return
    }&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN data-teams="true"&gt;&lt;SPAN class="ui-provider a b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak"&gt;&lt;BR /&gt;New code:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;// parcel_Documents Fields
var parcelDocumentsGlobalID_field = "GlobalID"

// parcel Fields
var parcelGlobalID_field = "GlobalID"
var parcelType_field = "type"

var relatedRecords = FeatureSetByRelationshipClass($feature, "parcel_Documents", [parcelDocumentsGlobalID_field], false);
var parcelFeatures = FeatureSetByName($datastore, "parcel", [parcelGlobalID_field ,parcelType_field], false)
var globalIDs = []
for (var record in relatedRecords){
    var rg = record.GlobalID;
    Push(globalIDs, rg);
}

if (Count(globalIDs)&amp;lt;1){
   return
    }

var filteredLandStatusFeatures = Filter(landStatusFeatures, 'GlobalID IN @globalIDs' ) 

var cnt = Count(filteredParcelFeatures)

return {
    "errorMessage": Text(cnt)
}&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN data-teams="true"&gt;&lt;SPAN class="ui-provider a b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 15:07:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/arcade-filter-slq-in-array-issue/m-p/1552809#M1614</guid>
      <dc:creator>Jake_S</dc:creator>
      <dc:date>2024-10-28T15:07:02Z</dc:date>
    </item>
  </channel>
</rss>

