<?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 SQL Statement within Attribute Rule Calculation Error in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/sql-statement-within-attribute-rule-calculation/m-p/1195608#M482</link>
    <description>&lt;P&gt;Hello Everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having an issue with an sql statement within a calculation attribute rule. So basically I want to filter related data based of guid and a 'last clean' date field that's not null, AND is also within this year. The first two statements are fine on thier own, but the calculation fails when I query for year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a part of my code for context&lt;/P&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;&amp;nbsp;&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;var CB_gid = $feature.GlobalID;
var this_year= Year(now());
var filter_statement = 'guid = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/58275"&gt;@CB&lt;/a&gt;_gid AND last_cleaned IS NOT Null AND YEAR(last_cleaned) = @this_year)'

//an example of this which works fine in pro can be seen below
guid = '{F5C7CC47-6B71-439A-A144-834C9696C262}' AND last_cleaned IS NOT Null AND YEAR(last_cleaned) = '2022'&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;&amp;nbsp;&lt;/P&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;This a part of the error that occurs when trying to run the calculation.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="arcade_error.png" style="width: 411px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/46719i2573484693C70C81/image-size/large?v=v2&amp;amp;px=999" role="button" title="arcade_error.png" alt="arcade_error.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Just for some more context, this filter is just one of possible three filters that occurs based off three if statements. The other two work fine, just not this one. And there is also a workaround I can do with more arcade variables for beginning of the year date and end of year date, but id rather have it in sql statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Mon, 25 Jul 2022 22:03:02 GMT</pubDate>
    <dc:creator>OliverSandoval_p</dc:creator>
    <dc:date>2022-07-25T22:03:02Z</dc:date>
    <item>
      <title>SQL Statement within Attribute Rule Calculation Error</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/sql-statement-within-attribute-rule-calculation/m-p/1195608#M482</link>
      <description>&lt;P&gt;Hello Everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having an issue with an sql statement within a calculation attribute rule. So basically I want to filter related data based of guid and a 'last clean' date field that's not null, AND is also within this year. The first two statements are fine on thier own, but the calculation fails when I query for year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a part of my code for context&lt;/P&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;&amp;nbsp;&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;var CB_gid = $feature.GlobalID;
var this_year= Year(now());
var filter_statement = 'guid = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/58275"&gt;@CB&lt;/a&gt;_gid AND last_cleaned IS NOT Null AND YEAR(last_cleaned) = @this_year)'

//an example of this which works fine in pro can be seen below
guid = '{F5C7CC47-6B71-439A-A144-834C9696C262}' AND last_cleaned IS NOT Null AND YEAR(last_cleaned) = '2022'&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;&amp;nbsp;&lt;/P&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;This a part of the error that occurs when trying to run the calculation.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="arcade_error.png" style="width: 411px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/46719i2573484693C70C81/image-size/large?v=v2&amp;amp;px=999" role="button" title="arcade_error.png" alt="arcade_error.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Just for some more context, this filter is just one of possible three filters that occurs based off three if statements. The other two work fine, just not this one. And there is also a workaround I can do with more arcade variables for beginning of the year date and end of year date, but id rather have it in sql statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2022 22:03:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/sql-statement-within-attribute-rule-calculation/m-p/1195608#M482</guid>
      <dc:creator>OliverSandoval_p</dc:creator>
      <dc:date>2022-07-25T22:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Statement within Attribute Rule Calculation Error</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/sql-statement-within-attribute-rule-calculation/m-p/1195745#M483</link>
      <description>&lt;P&gt;According to your working query, 2022 should be provided as string, but it's an integer.&lt;/P&gt;&lt;P&gt;Try these approaches:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// convert this_year to string
var CB_gid = $feature.GlobalID;
var this_year= Text(Year(Now()));
var filter_statement = 'guid = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/58275"&gt;@CB&lt;/a&gt;_gid AND last_cleaned IS NOT Null AND YEAR(last_cleaned) = @this_year)'&lt;/LI-CODE&gt;&lt;LI-CODE lang="javascript"&gt;// take care of the types yourself
var filter_statement = `guid = '${$feature.GlobalID}' AND last_cleaned IS NOT Null AND YEAR(last_cleaned) = '${Year(Now())}')`&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 06:03:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/sql-statement-within-attribute-rule-calculation/m-p/1195745#M483</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-07-26T06:03:04Z</dc:date>
    </item>
  </channel>
</rss>

