Select to view content in your preferred language

Arcade to configure pop up using schema

262
4
03-10-2025 12:33 PM
Labels (1)
CherylWheeler11
Regular Contributor

Would anybody have any sample arcade code which extracts the schema of a layer to configure the pop-up such that it iterates through all the fields and displays the alias of those which are not empty, along with their value in a table?

(layer has 90 fields, so I need a way to do it iteratively) 

I am struggling with returning the relevant fields and values into a nicely formatted table.

Many thanks for any pointers.

0 Kudos
4 Replies
ZachBodenner
MVP Regular Contributor

Here's one method that Johannes Lindner has provided a few times here and there. There are some others, and I use one that requires identifying all of the fields, which I prefer since I can order them as desired. I don't find that too onerous, I just use Excel exports to copy-paste formatted lists for Arcade, but since you specify just pulling from the data schema, this is a straightforward solution.

Happy mapping,
- Zach
CherylWheeler11
Regular Contributor

Thanks very much Zach!

This is along the lines of what I have been trying, but I have a query .....using the statement 

var fieldData = Schema($feature).fields

creates a dictionary, but how do I generate an array of the fields from the dictionary. In the example provided the 'fieldstoinclude' value is set, whereas I would like to iterate through all of the fields. Can I do that in a loop directly from the dictionary?

 

0 Kudos
KenBuja
MVP Esteemed Contributor

This is one way I do it for a particular map. The layer has a table with fields for 15 different species, along with other fields to describe the feature's location. For each species, the field name is MAX_Species (MAX_Austra, MAX_Crater, MAX_Globic, etc) and the alias is Species (Australien, Craterifor, Globiceps, etc). Each field contains either a 0 or 1 to show if the species is present.

I use this script in a Text element

Expects($feature, 'MAX*')
var theSchema = Schema($feature);
var fields = theSchema['fields'];
var species = [];
for (var i in fields) {
   if (Find('MAX', fields[i]['name']) > -1 && $feature[fields[i]['name']] == 1) {
     Push(species,fields[i]['alias']);
   }
}

return `• ${Concatenate(species,'\n• ')}`;

which returns this popup

Snag_18d27ff.png

 

0 Kudos
CherylWheeler11
Regular Contributor

Ah, this looks promising. Let me give it a go. Thanks Ken

0 Kudos