<?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 Expression for Labels in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcade-expression-for-labels/m-p/1353841#M82937</link>
    <description>&lt;P&gt;I am trying to get a field value from a feature using Arcade and pass it to a label for a chart in a popup.&lt;/P&gt;&lt;P&gt;I create the expression outside the JavaScript to get the field value:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;script type="text/arcgis-arcade" id="field-name"&amp;gt;
  var label = $feature.Field2;
  return {label};
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Then I reference the script:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var arcadeFields = document.getElementById("field-name").text;&lt;/LI-CODE&gt;&lt;P&gt;Finally, I use the variable in the label property of the popupTemplate:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;popupTemplate: {
title: "Layer1",
fieldInfos: [{
fieldName: "Field18",
label: "Field 18 label"
},
{
fieldName: "Field25",
label: arcadeFields
}
],&lt;/LI-CODE&gt;&lt;P&gt;It is almost working as intended, only the label for the chart shows the Arcade expression shown below, but not the actual field value.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.jpg" style="width: 354px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/87242i941A45A4C56B5E1F/image-dimensions/354x246?v=v2" width="354" height="246" role="button" title="Untitled.jpg" alt="Untitled.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;How do I get the Arcade script to return the field value and not the expression?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a &lt;A href="https://codepen.io/John-Max-the-sans/pen/qBgyoVp" target="_self"&gt;codepen&amp;nbsp;&lt;/A&gt;of it in action if you click on one of the parcels with a value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Nov 2023 22:06:21 GMT</pubDate>
    <dc:creator>JohnMax</dc:creator>
    <dc:date>2023-11-27T22:06:21Z</dc:date>
    <item>
      <title>Arcade Expression for Labels</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcade-expression-for-labels/m-p/1353841#M82937</link>
      <description>&lt;P&gt;I am trying to get a field value from a feature using Arcade and pass it to a label for a chart in a popup.&lt;/P&gt;&lt;P&gt;I create the expression outside the JavaScript to get the field value:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;script type="text/arcgis-arcade" id="field-name"&amp;gt;
  var label = $feature.Field2;
  return {label};
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Then I reference the script:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var arcadeFields = document.getElementById("field-name").text;&lt;/LI-CODE&gt;&lt;P&gt;Finally, I use the variable in the label property of the popupTemplate:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;popupTemplate: {
title: "Layer1",
fieldInfos: [{
fieldName: "Field18",
label: "Field 18 label"
},
{
fieldName: "Field25",
label: arcadeFields
}
],&lt;/LI-CODE&gt;&lt;P&gt;It is almost working as intended, only the label for the chart shows the Arcade expression shown below, but not the actual field value.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.jpg" style="width: 354px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/87242i941A45A4C56B5E1F/image-dimensions/354x246?v=v2" width="354" height="246" role="button" title="Untitled.jpg" alt="Untitled.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;How do I get the Arcade script to return the field value and not the expression?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a &lt;A href="https://codepen.io/John-Max-the-sans/pen/qBgyoVp" target="_self"&gt;codepen&amp;nbsp;&lt;/A&gt;of it in action if you click on one of the parcels with a value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2023 22:06:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcade-expression-for-labels/m-p/1353841#M82937</guid>
      <dc:creator>JohnMax</dc:creator>
      <dc:date>2023-11-27T22:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression for Labels</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcade-expression-for-labels/m-p/1355344#M82983</link>
      <description>&lt;P&gt;fieldInfo.label doesn't take Arcade expressions. Arcade can only be defined in 2 places inside popups: expressionInfos, and ExpressionContent elements. To accomplish what you're attempting, you need an ExpressionContent element. This gives you full control over popup elements all within the scope of an Arcade expression. The expression itself needs to return the content type you want...in this case a chart. That chart's labels and values can be calculated using any Arcade function within the expression.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's an example of the expression:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var label = Text($feature.Field2);
var attributes = {
  "Field 18 label": $feature.Field18
};
attributes[label] = $feature.Field25;

var fields = [];

for (var a in attributes){
  Push(fields, a);
}

return {
  type: "media",
  attributes,
  mediaInfos: [{
    type: "piechart",
    title: "Count by type",
    value: {
      fields
    }
  }]
};&lt;/LI-CODE&gt;&lt;P&gt;And how you would reference it in your app:&amp;nbsp;&lt;A href="https://codepen.io/kekenes/pen/rNPqymw?editors=1000" target="_blank"&gt;https://codepen.io/kekenes/pen/rNPqymw?editors=1000&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2023 20:01:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcade-expression-for-labels/m-p/1355344#M82983</guid>
      <dc:creator>KristianEkenes</dc:creator>
      <dc:date>2023-11-30T20:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression for Labels</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcade-expression-for-labels/m-p/1355453#M82984</link>
      <description>&lt;P&gt;Brilliant!&amp;nbsp; Thanks so much for the help.&amp;nbsp; I could never have figured this out on my own.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2023 23:06:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcade-expression-for-labels/m-p/1355453#M82984</guid>
      <dc:creator>JohnMax</dc:creator>
      <dc:date>2023-11-30T23:06:58Z</dc:date>
    </item>
  </channel>
</rss>

