<?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: Help creating dictionary lookup from variable in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/help-creating-dictionary-lookup-from-variable/m-p/1300057#M52874</link>
    <description>&lt;P&gt;This worked a treat. Thanks. Final code below (changed the way the iif statements worked as well as they weren't returning the expected results - now uses a function to compare labels meaning it can find any Asbestos reference and not just in "Hazard" points).&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var ftype = $feature.Feature_Type
var label = $feature.Label

function HazCat(txt,type) {
    if (Find("Asbestos", txt, 0)&amp;gt;-1) {
        return "AsbestosHazard";
    } else {
        return type;
    }
}

var symbol = Replace(Replace(Replace(Replace(HazCat(label,ftype),' ' , '' ), '(' , '' ), ')' , '' ), '-' , '' );

var d = Dictionary('Bore', 1,     'ExternalGate', 2,     'ExternalGateLocked', 3,     'GravelPit', 4,     'Hazard', 5,     'AsbestosHazard', 6,     'Helipad', 7,     'House', 8,     'InternalGate', 9,     'NoAccess', 10,     'OtherInfrastructure', 11,     'PhoneReception', 12,     'Shed', 13,     'WaterPoint', 14,     'WaterPointTank', 15)

var category = d[symbol]

return category&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Jun 2023 00:14:04 GMT</pubDate>
    <dc:creator>LindsayRaabe_FPCWA</dc:creator>
    <dc:date>2023-06-16T00:14:04Z</dc:date>
    <item>
      <title>Help creating dictionary lookup from variable</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/help-creating-dictionary-lookup-from-variable/m-p/1299012#M52797</link>
      <description>&lt;P&gt;I'm trying to write an expression to create custom symbology in a feature service. Currently I've made it this far:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var ftype = $feature.Feature_Type
var label = $feature.Label
var symbol = Replace(Replace(Replace(Replace(iif(ftype == "Hazard",iif(label == "Asbestos","Asbestos Hazard","Hazard"),ftype), ' ' , '' ), '(' , '' ), ')' , '' ), '-' , '' )

var d = Dictionary('Bore', 1, 	'ExternalGate', 2, 	'ExternalGateLocked', 3, 	'GravelPit', 4, 	'Hazard', 5, 	'AsbestosHazard', 6, 	'Helipad', 7, 	'House', 8, 	'InternalGate', 9, 	'NoAccess', 10, 	'OtherInfrastructure', 11, 	'PhoneReception', 12, 	'Shed', 13, 	'WaterPoint', 14, 	'WaterPointTank', 15)

var category = d.symbol

return category&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The &lt;STRONG&gt;Replace&lt;/STRONG&gt; functions are removing any spaces, brackets and dashes from the value returned from the $feature.Feature_Type value and work fine. The issue I'm having is I can't get the number value out of the dictionary using a variable as an input. I know this must be possible (or it would be pointless having dictionaries) but I can't figure out how to get the&amp;nbsp;&lt;STRONG&gt;d.symbol&lt;/STRONG&gt;&amp;nbsp;(line 7) to use the value returned at line 4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I change line 7 to say:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var category = d.Bore&lt;/LI-CODE&gt;&lt;P&gt;...then it all works. As soon as I change d.Bore back to d.symbol then it fails (even though the variable symbol is returning "Bore").&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried formatting &lt;STRONG&gt;d.symbol&lt;/STRONG&gt; through text concatenation, but that didn't work either.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 04:00:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/help-creating-dictionary-lookup-from-variable/m-p/1299012#M52797</guid>
      <dc:creator>LindsayRaabe_FPCWA</dc:creator>
      <dc:date>2023-06-14T04:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: Help creating dictionary lookup from variable</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/help-creating-dictionary-lookup-from-variable/m-p/1299020#M52798</link>
      <description>&lt;P&gt;So there are two ways to retrieve (and set) values from a dictionary:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var d = {"A": 1}

// Dot notation
Console(d.A)  // 1
d.B = 2
Console(d.B)  // 2

// Bracket notation
Console(d["A"])  // 1
d["C"] = 3
Console(d["C"])  // 3&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dot notation is quicker to write and (imo) easier to read, but it does not resolve variables. In your case, it looks for the key "symbol", doesn't find it and raises an error.&lt;/P&gt;&lt;P&gt;To make this work, you need the bracket notation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var category = d[symbol]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 06:16:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/help-creating-dictionary-lookup-from-variable/m-p/1299020#M52798</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-06-14T06:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: Help creating dictionary lookup from variable</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/help-creating-dictionary-lookup-from-variable/m-p/1299029#M52800</link>
      <description>&lt;P&gt;Awesome. Thank you. I'll give that a try tomorrow.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 07:11:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/help-creating-dictionary-lookup-from-variable/m-p/1299029#M52800</guid>
      <dc:creator>LindsayRaabe_FPCWA</dc:creator>
      <dc:date>2023-06-14T07:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: Help creating dictionary lookup from variable</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/help-creating-dictionary-lookup-from-variable/m-p/1300057#M52874</link>
      <description>&lt;P&gt;This worked a treat. Thanks. Final code below (changed the way the iif statements worked as well as they weren't returning the expected results - now uses a function to compare labels meaning it can find any Asbestos reference and not just in "Hazard" points).&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var ftype = $feature.Feature_Type
var label = $feature.Label

function HazCat(txt,type) {
    if (Find("Asbestos", txt, 0)&amp;gt;-1) {
        return "AsbestosHazard";
    } else {
        return type;
    }
}

var symbol = Replace(Replace(Replace(Replace(HazCat(label,ftype),' ' , '' ), '(' , '' ), ')' , '' ), '-' , '' );

var d = Dictionary('Bore', 1,     'ExternalGate', 2,     'ExternalGateLocked', 3,     'GravelPit', 4,     'Hazard', 5,     'AsbestosHazard', 6,     'Helipad', 7,     'House', 8,     'InternalGate', 9,     'NoAccess', 10,     'OtherInfrastructure', 11,     'PhoneReception', 12,     'Shed', 13,     'WaterPoint', 14,     'WaterPointTank', 15)

var category = d[symbol]

return category&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 00:14:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/help-creating-dictionary-lookup-from-variable/m-p/1300057#M52874</guid>
      <dc:creator>LindsayRaabe_FPCWA</dc:creator>
      <dc:date>2023-06-16T00:14:04Z</dc:date>
    </item>
  </channel>
</rss>

