<?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 Using Arcade to create a sort field in a Dashboard in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/using-arcade-to-create-a-sort-field-in-a-dashboard/m-p/1318479#M8306</link>
    <description>&lt;P&gt;Edit:&amp;nbsp; I got more written, code example is below.&amp;nbsp; I can see, using a console command, that the new order_by field is populated the way I want, and all the other fields have their data in them, but when I hit 'Done' on the data expression, the Dashboard tells me there's no data from the expression.&amp;nbsp; &amp;nbsp;What am I doing wrong that there's no data when I can see it from a Console command just before the Return at the end?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I've been trying to figure out how to use Arcade to create a field in a Dashboard, and then use that field to sort a Serial Chart, but I'm new to Arcade and am having trouble figuring it out.&amp;nbsp; I know some Python (self-taught), but my couple days with Arcade haven't yielded much fruit yet.&lt;/P&gt;&lt;P&gt;I can access my portal item, and get to the schema, but I'm not understanding how to create a new field in the table, and then populate that field based on a value in another field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Connect to portal item, the specific table I want to add a field to
// in this case. Portal and item ID replaced with x's
var fs = FeatureSetByPortalItem(
    Portal('xxx'),
    'xxx',
    1,
    ['*'],
    false
)

// get schema for the table. 
// What is ['fields'] doing here exactly?
var out_fields = Schema(fs)['fields']

// add a new field to the schema for the value to sort by.  
// I can see this adding a field to the schema using a console command.
Push(
    out_fields,
    {name: 'order_by', alias: 'Order', type: 'esriFieldTypeString'}
)   
// Use updated schema to create a new dict
var out_dict = {
    fields: out_fields,
    geometryType: '',
    features: []
}

// Iterate over features and populate order_by field
for (var f in fs){
    
    // Create dict from existing attributes
    var atts = Dictionary(Text(f))['attributes']
    
    // The decode mapping
    var d = Decode(
        f['The_Field_name'],
        "INS", "A",
        "RAN", "B",
        "TXT", "C",
        "FOR", "D",
        "EXP", "E",
        "PUR", "F",
        "HIT", "G",
        "FAL", "H",
        "REW", "I",
        "CAL", "J",
        ""
    )
    
    // Setting the field order_by to the decode value
    atts['order_by'] = d
    
    // This makes the features of out_dict, which were empty when we 
    // created it above, to the value of the atts dict I think?
    Push(
        out_dict['features'],
        atts)
        
}
// Running a console command on out_dict at this point shows all my fields 
// and that they have date in every field, and I can see order_by is
// populated, but when I hit Done and run it, I get No Data.
Return FeatureSet(Text(out_dict)) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is where I get lost.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I access the values in any particular field in the table I'm calling to evaluate them, and then how do I write whatever corresponding value I want to the new field created?&lt;/P&gt;&lt;P&gt;I was able to do it successfully in our Portal Map Viewer, but I'm struggling to figure out how to do it in the Dashboard itself.&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&amp;nbsp; And if I need to clarify anything, please let me know.&lt;/P&gt;&lt;P&gt;EDIT: See top of post, I've gotten more code written, but can't figure out why it's empty when I hit done.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Ethan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Aug 2023 12:53:18 GMT</pubDate>
    <dc:creator>EthanHunt1</dc:creator>
    <dc:date>2023-08-17T12:53:18Z</dc:date>
    <item>
      <title>Using Arcade to create a sort field in a Dashboard</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/using-arcade-to-create-a-sort-field-in-a-dashboard/m-p/1318479#M8306</link>
      <description>&lt;P&gt;Edit:&amp;nbsp; I got more written, code example is below.&amp;nbsp; I can see, using a console command, that the new order_by field is populated the way I want, and all the other fields have their data in them, but when I hit 'Done' on the data expression, the Dashboard tells me there's no data from the expression.&amp;nbsp; &amp;nbsp;What am I doing wrong that there's no data when I can see it from a Console command just before the Return at the end?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I've been trying to figure out how to use Arcade to create a field in a Dashboard, and then use that field to sort a Serial Chart, but I'm new to Arcade and am having trouble figuring it out.&amp;nbsp; I know some Python (self-taught), but my couple days with Arcade haven't yielded much fruit yet.&lt;/P&gt;&lt;P&gt;I can access my portal item, and get to the schema, but I'm not understanding how to create a new field in the table, and then populate that field based on a value in another field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Connect to portal item, the specific table I want to add a field to
// in this case. Portal and item ID replaced with x's
var fs = FeatureSetByPortalItem(
    Portal('xxx'),
    'xxx',
    1,
    ['*'],
    false
)

// get schema for the table. 
// What is ['fields'] doing here exactly?
var out_fields = Schema(fs)['fields']

// add a new field to the schema for the value to sort by.  
// I can see this adding a field to the schema using a console command.
Push(
    out_fields,
    {name: 'order_by', alias: 'Order', type: 'esriFieldTypeString'}
)   
// Use updated schema to create a new dict
var out_dict = {
    fields: out_fields,
    geometryType: '',
    features: []
}

// Iterate over features and populate order_by field
for (var f in fs){
    
    // Create dict from existing attributes
    var atts = Dictionary(Text(f))['attributes']
    
    // The decode mapping
    var d = Decode(
        f['The_Field_name'],
        "INS", "A",
        "RAN", "B",
        "TXT", "C",
        "FOR", "D",
        "EXP", "E",
        "PUR", "F",
        "HIT", "G",
        "FAL", "H",
        "REW", "I",
        "CAL", "J",
        ""
    )
    
    // Setting the field order_by to the decode value
    atts['order_by'] = d
    
    // This makes the features of out_dict, which were empty when we 
    // created it above, to the value of the atts dict I think?
    Push(
        out_dict['features'],
        atts)
        
}
// Running a console command on out_dict at this point shows all my fields 
// and that they have date in every field, and I can see order_by is
// populated, but when I hit Done and run it, I get No Data.
Return FeatureSet(Text(out_dict)) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is where I get lost.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I access the values in any particular field in the table I'm calling to evaluate them, and then how do I write whatever corresponding value I want to the new field created?&lt;/P&gt;&lt;P&gt;I was able to do it successfully in our Portal Map Viewer, but I'm struggling to figure out how to do it in the Dashboard itself.&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&amp;nbsp; And if I need to clarify anything, please let me know.&lt;/P&gt;&lt;P&gt;EDIT: See top of post, I've gotten more code written, but can't figure out why it's empty when I hit done.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Ethan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 12:53:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/using-arcade-to-create-a-sort-field-in-a-dashboard/m-p/1318479#M8306</guid>
      <dc:creator>EthanHunt1</dc:creator>
      <dc:date>2023-08-17T12:53:18Z</dc:date>
    </item>
  </channel>
</rss>

