Select to view content in your preferred language

SWEET for ArcGIS Arcade - Create dropdown list for a field based on a hosted table

1233
1
03-29-2022 06:12 PM
Kaz
by
Occasional Contributor

Hi all, 

I am building an application in SWEET for ArcGIS and want to create a dynamic drop down list for a field. I want the options to show possible values based on a hosted lookup table; basically a dynamic domain. I can't actually use a domain so I need to figure out how to do this...

There is an example in SWEET for creating a static list of possible values, but I'm not sure how to do this by reading off a table. In python, I would read the table, and for each record in the field, I'd add the value to the list. Then I would return the list, and those would be the options. 

I'm not really sure how to achieve this in Arcade, it seems like it uses "arrays" instead of "lists" for this functionality. How do I add values to an array in Arcade?

Here's how I wish the script would work...

var TestingPolicies = FeatureSetByName($map,"Testingpolicy")
var options = []//create empty list
for (var record in TestingPolicies){
    var option = record.DCA_Type
    options.append(option)//add each option to the list
}
return options

 

And here's the sample code for making a 'static' list using the SWEET configuration "Scripted Choice for [Field Name]": 

return {
  choices: [
    {
      value: "A",
      label: "AAA"
    },
    {
      value: "B",
      label: "BBB"
    },
    {
      value: "C",
      label: "CCC"
    }
  ],
  static: true // If static, the script will only ever execute once. Use for lists that do not change
};

 

Tags (3)
0 Kudos
1 Reply
JohannesLindner
MVP Frequent Contributor

I have no clue about SWEET and if this will work, but you're looking for the Push function.

var TestingPolicies = FeatureSetByName($map,"Testingpolicy")
// if you have multiples of each DCA_Type in that table, you might want to use Distinct:
//TestingPolicies = Distinct(TestingPolicies, "DCA_Type")
var options = []//create empty list
for (var record in TestingPolicies){
    var option = record.DCA_Type
    Push(options, option)//add each option to the list
}
return options

Have a great day!
Johannes
0 Kudos