<?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 Arcade Label Expression Value Substitutions in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342201#M74487</link>
    <description>&lt;P&gt;I have a numerical attribute field containing integer values and would like to have the label expression display a corresponding value for each integer. I have created a dictionary representing these values.&lt;/P&gt;&lt;P&gt;However, the label expression dialogue indicates an error in line 2:&lt;FONT color="#FF0000"&gt; Invalid Key&lt;/FONT&gt;.&amp;nbsp;&lt;FONT color="#000000"&gt;I cannot see anything wrong with the format of the dictionary based on other examples found within the forums.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;The Arcade expression is shown below.&lt;/FONT&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var stuff = {
  0: "SCC",
  101: "SEP",
  4: "CLT",
  23: "CGS",
  8: "CTR",
  7: "CTH",
  14: "DSW",
  9: "ECT",
  5: "FTH",
  21: "GPS",
  10: "GSL",
  3: "ITH",
  22: "ITS",
  13: "ISH",
  20: "OSR",
  17: "PTC",
  26: "PCT",
  24: "SAL",
  18: "STC",
  15: "SWR",
  19: "STR",
  6: "TFA",
  12: "3SS",
  11: "2SS",
  100: "GPE",
  25: "WHI",
  102: "RET",
  103: "TSI",
  104: "POL"
};

var keyField = "Type"; //this is the attribute field with the integer values
var lookupKey = $feature[keyField];
var lookupResult = Dictionary(stuff)[lookupKey];

&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 26 Oct 2023 17:45:16 GMT</pubDate>
    <dc:creator>ZacharyHart</dc:creator>
    <dc:date>2023-10-26T17:45:16Z</dc:date>
    <item>
      <title>Arcade Label Expression Value Substitutions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342201#M74487</link>
      <description>&lt;P&gt;I have a numerical attribute field containing integer values and would like to have the label expression display a corresponding value for each integer. I have created a dictionary representing these values.&lt;/P&gt;&lt;P&gt;However, the label expression dialogue indicates an error in line 2:&lt;FONT color="#FF0000"&gt; Invalid Key&lt;/FONT&gt;.&amp;nbsp;&lt;FONT color="#000000"&gt;I cannot see anything wrong with the format of the dictionary based on other examples found within the forums.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;The Arcade expression is shown below.&lt;/FONT&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var stuff = {
  0: "SCC",
  101: "SEP",
  4: "CLT",
  23: "CGS",
  8: "CTR",
  7: "CTH",
  14: "DSW",
  9: "ECT",
  5: "FTH",
  21: "GPS",
  10: "GSL",
  3: "ITH",
  22: "ITS",
  13: "ISH",
  20: "OSR",
  17: "PTC",
  26: "PCT",
  24: "SAL",
  18: "STC",
  15: "SWR",
  19: "STR",
  6: "TFA",
  12: "3SS",
  11: "2SS",
  100: "GPE",
  25: "WHI",
  102: "RET",
  103: "TSI",
  104: "POL"
};

var keyField = "Type"; //this is the attribute field with the integer values
var lookupKey = $feature[keyField];
var lookupResult = Dictionary(stuff)[lookupKey];

&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 26 Oct 2023 17:45:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342201#M74487</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2023-10-26T17:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Label Expression Value Substitutions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342216#M74489</link>
      <description>&lt;P&gt;A key in the dictionary must be a string, not a number. You'll have to convert your field value to a string, in addition. Here's an example that works.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var stuff = {
  "0": "SCC",
  "101": "SEP",
  "4": "CLT",
  "23": "CGS"
};

var test = Text(0);
var lookupResult = Dictionary(stuff)[test]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 18:06:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342216#M74489</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-10-26T18:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Label Expression Value Substitutions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342219#M74490</link>
      <description>&lt;P&gt;I should have mentioned I tried that as well but when doing this I'm given an error of field not found. I know the format for Arcade attribute labels is $feature.fieldname&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var stuff = {
  "0": "SCC",
  "101": "SEP",
  "4": "CLT",
  "23": "CGS",
  "8": "CTR",
  "7": "CTH",
  "14": "DSW",
  "9": "ECT",
  "5": "FTH",
  "21": "GPS",
  "10": "GSL",
  "3": "ITH",
  "22": "ITS",
  "13": "ISH",
  "20": "OSR",
  "17": "PTC",
  "26": "PCT",
  "24": "SAL",
  "18": "STC",
  "15": "SWR",
  "19": "STR",
  "6": "TFA",
  "12": "3SS",
  "11": "2SS",
  "100": "GPE",
  "25": "WHI",
  "102": "RET",
  "103": "TSI",
  "104": "POL"
};

var keyField = "Type"; 

// Look up the value based on the key from the field
var lookupKey = $feature[keyField];
var lookupResult = Dictionary(stuff)[lookupKey];
return lookUpResult;&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 26 Oct 2023 18:17:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342219#M74490</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2023-10-26T18:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Label Expression Value Substitutions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342228#M74491</link>
      <description>&lt;P&gt;Here's an example using the sample dataset in the &lt;A href="https://developers.arcgis.com/arcade/playground/" target="_self"&gt;Playground&lt;/A&gt; (with the first key changed to "1" to get a result)&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Returns the first feature in the layer
var feat = First(
  // Fetches features from a public portal item
  FeatureSetByPortalItem(
    Portal("https://www.arcgis.com"),
    // portal item id
    "7b1fb95ab77f40bf8aa09c8b59045449",
    0, // layer id
    ["*"], // fields to include
    false // include or exclude geometry
  )
);

var stuff = {
  "1": "SCC",
  "101": "SEP",
  "4": "CLT",
  "23": "CGS"
};

var keyField = 'HasData'
var lookupKey = Text(feat[keyField]);

return Dictionary(stuff)[lookupKey]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="playgroudn.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/84165i7071DEF545112B42/image-size/medium?v=v2&amp;amp;px=400" role="button" title="playgroudn.png" alt="playgroudn.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 18:32:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342228#M74491</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-10-26T18:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Label Expression Value Substitutions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342232#M74492</link>
      <description>&lt;P&gt;Also note that I modified the first response to include that you also have to convert the numeric attribute to a string to return a value in the Dictionary.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 18:36:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342232#M74492</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-10-26T18:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Label Expression Value Substitutions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342234#M74493</link>
      <description>&lt;P&gt;I noticed that and i'm still getting the same error about field not found. Perhaps this is an issue with the label expression builder? I'm trying to fetch attributes with that interface. (ArcGIS Pro 3.1.3)&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 18:39:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342234#M74493</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2023-10-26T18:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Label Expression Value Substitutions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342246#M74494</link>
      <description>&lt;P&gt;You have to use the &lt;A href="https://developers.arcgis.com/arcade/function-reference/feature_functions/#expects" target="_self"&gt;Expects&lt;/A&gt; function at the top of the script when using a variable for the field.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Expects($feature, "Type")
var stuff = {
  "0": "SCC",
  "101": "SEP",
  "4": "CLT",
  "23": "CGS"
};
var keyField = "Type"; 

// Look up the value based on the key from the field
var lookupKey = Text($feature[keyField]);
var lookupResult = Dictionary(stuff)[lookupKey];
return lookUpResult;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 18:54:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342246#M74494</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-10-26T18:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Label Expression Value Substitutions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342252#M74496</link>
      <description>&lt;P&gt;Ok new clues. I'm going to mark your other response as the solution since it got us to where we need to be, but the rest looks like we have found a potential bug.&amp;nbsp;&lt;/P&gt;&lt;P&gt;A colleague tested for me and the expression works just fine in AGO. For the heck of it, I saved a copy of that layer in AGO with the working label expression and brought it into Pro. Labeling failed to work. Checked the expression and same error about field not found.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I tried to add&amp;nbsp;Expects($feature, "Type")&lt;/P&gt;&lt;P&gt;and that returns a new error of invalid JSON. So everything works fine in AGO but there's a problem with this solution in Pro.&lt;/P&gt;&lt;P&gt;Thanks for everything!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 19:04:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342252#M74496</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2023-10-26T19:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Label Expression Value Substitutions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342342#M74505</link>
      <description>&lt;P&gt;Not sure why an arcade expression would work in AGO and not in Pro, but I've come up with a different way to write this that is working in Pro:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;var stuff = {
  "0": "SCC",
  "101": "SEP",
  "4": "CLT",
  "23": "CGS",
  "8": "CTR",
  "7": "CTH",
  "14": "DSW",
  "9": "ECT",
  "5": "FTH",
  "21": "GPS",
  "10": "GSL",
  "3": "ITH",
  "22": "ITS",
  "13": "ISH",
  "20": "OSR",
  "17": "PTC",
  "26": "PCT",
  "24": "SAL",
  "18": "STC",
  "15": "SWR",
  "19": "STR",
  "6": "TFA",
  "12": "3SS",
  "11": "2SS",
  "100": "GPE",
  "25": "WHI",
  "102": "RET",
  "103": "TSI",
  "104": "POL"
};

return stuff[Text($feature.Type)]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 20:51:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342342#M74505</guid>
      <dc:creator>ElisabethFenn</dc:creator>
      <dc:date>2023-10-26T20:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Label Expression Value Substitutions</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342397#M74513</link>
      <description>&lt;P&gt;Thanks for this Elisabeth!&lt;/P&gt;&lt;P&gt;I'm curious about the disparity between AGO in Pro in the implementation of Arcade regarding dictionaries now.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 22:12:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcade-label-expression-value-substitutions/m-p/1342397#M74513</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2023-10-26T22:12:49Z</dc:date>
    </item>
  </channel>
</rss>

