<?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: Getting $feature attribute using brackets and variable not working. in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/getting-feature-attribute-using-brackets-and/m-p/1149499#M335</link>
    <description>&lt;P&gt;I'm sure there are more elegant solutions...&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var attributes = Dictionary(Text($feature))["attributes"]

var field_names = ["ASSETTYPE", "OBJECTID"]
for(var i in field_names) {
  Console(attributes[field_names[i]])
}&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 02 Mar 2022 10:33:05 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-03-02T10:33:05Z</dc:date>
    <item>
      <title>Getting $feature attribute using brackets and variable not working.</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/getting-feature-attribute-using-brackets-and/m-p/1149481#M334</link>
      <description>&lt;P&gt;Trying to access a feature's attribute using the bracket notation does not work when using a variable (unless it is accessed at least once using a string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you take a look at the snippet below. This gives an error&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fldName = "ASSETTYPE";
Console($feature[fldName]);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error message is :&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#FF0000"&gt;Invalid expression.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;Error on line 2.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;Field not found ASSETTYPE&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While If I try to use the snippet below. It works without an error&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var ftrValue = $feature["ASSETTYPE"];
Console(ftrValue);
var fldName = "ASSETTYPE";
Console($feature[fldName]);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas how I can work around this restriction? I have a dynamic list of fields that I am trying to use to get values from the feature.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One thing to note is that if I use OBJECTID for the first snippet, it does not give any errors and works without having to access the field first using an inline string!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 09:02:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/getting-feature-attribute-using-brackets-and/m-p/1149481#M334</guid>
      <dc:creator>omar-marji</dc:creator>
      <dc:date>2022-03-02T09:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Getting $feature attribute using brackets and variable not working.</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/getting-feature-attribute-using-brackets-and/m-p/1149499#M335</link>
      <description>&lt;P&gt;I'm sure there are more elegant solutions...&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var attributes = Dictionary(Text($feature))["attributes"]

var field_names = ["ASSETTYPE", "OBJECTID"]
for(var i in field_names) {
  Console(attributes[field_names[i]])
}&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 02 Mar 2022 10:33:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/getting-feature-attribute-using-brackets-and/m-p/1149499#M335</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-03-02T10:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Getting $feature attribute using brackets and variable not working.</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/getting-feature-attribute-using-brackets-and/m-p/1149522#M336</link>
      <description>&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;Unfortunately, this still has the same issue and I am starting to think it is in the way the "verify" function works when creating the attribute rules.&lt;/P&gt;&lt;P&gt;Check the below scenario:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Console(Text($feature));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This results in the following object&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "geometry":{
    "x":####,
    "y":####,
    "z":0,
    "m":null,
    "spatialReference":{"wkid":####}
  },
  "attributes":{
    "GLOBALID":"{443094DA-F564-47D2-A07E-F47EA9B1C03A}",
    "OBJECTID":5
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While this scenario (although the attributes was accessed after the console call)&lt;/P&gt;&lt;LI-CODE lang="c"&gt;Console(Text($feature));
var assetType = $feature["ASSETTYPE"];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results in the following&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "geometry":{
    "x":####,
    "y":####,
    "z":0,
    "m":null,
    "spatialReference":{"wkid":####}
  },
  "attributes":{
    "ASSETTYPE":101,
    "GLOBALID":"{443094DA-F564-47D2-A07E-F47EA9B1C03A}",
    "OBJECTID":5
  }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 02 Mar 2022 12:25:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/getting-feature-attribute-using-brackets-and/m-p/1149522#M336</guid>
      <dc:creator>omar-marji</dc:creator>
      <dc:date>2022-03-02T12:25:23Z</dc:date>
    </item>
  </channel>
</rss>

