Customize popup using Arcade to loop through a text column

2510
1
09-28-2017 07:58 AM
RowenaTansley1
New Contributor III

Hi, I am looking for help on using Arcade to display complicated information in a popup in ArcGIS Online. I have complete control over my data and can modify it to work within the limitations of Arcade.

Currently Arcade can't access the information of related tables, so I got rid of the related tables and put all the information in one column in the main table with all the related information within the one column. Currently I am using JSON format to handles the relationships, but I can change this if anyone has other suggestions. Example JSON below (though it is minimized to 1 line in the table).

Can Arcade loop through this? I have tried and so far I just get a loop through each letter. I can reformat the string any way to make it more easily parsed.

Thanks in advance!


[{
"Type": "Complex",
"OBJECTID": "000000",
"Relationship1": [{
"TYPE": "Type1",
"OBJECTID": "111111"
},{
"TYPE": "Type2",
"OBJECTID": "222222"
}],
"Relationship2": [{
"TYPE": "Type1",
"OBJECTID": "333333"
},{
"TYPE": "Type2",
"OBJECTID": "444444"
}],
"Relationship3": [{
"TYPE": "Type1",
"OBJECTID": "555555"
},{
"TYPE": "Type2",
"OBJECTID": "666666"
}]
}]

0 Kudos
1 Reply
XanderBakker
Esri Esteemed Contributor

A bit late, but maybe it helps a bit. To present the data in a structured way in a pop-up based on the text (or json) you have now, is not possible. This is not really due to limitations of Arcade, but more due to the support for HTML returned by the Arcade expression. 

You could construct in a single Arcade expression a HTML table and return it, but it will be seen as plain text by the pop-up and show as such. See the expression below:

var txt = '[{"Type": "Complex", "OBJECTID": "000000","Relationship1": [{"TYPE": "Type1","OBJECTID": "111111"},{"TYPE": "Type2","OBJECTID": "222222"}],"Relationship2": [{"TYPE": "Type1","OBJECTID": "333333"},{"TYPE": "Type2","OBJECTID": "444444"}],"Relationship3": [{"TYPE": "Type1","OBJECTID": "555555"},{"TYPE": "Type2","OBJECTID": "666666"}]}]';

txt = Replace(txt, ' ', '');
txt = Replace(txt, '[', '');
txt = Replace(txt, '{', '');
txt = Replace(txt, ']', '');
txt = Replace(txt, '}', '');
txt = Replace(txt, '"', '');

var test1 = Split(txt, ',');
var test2 = "<table>";

for (var i in test1) {
    var row = test1[i];
    var lst_row = Split(row, ":");
    test2 += "<tr>"
    Console(row);
    for (var j in lst_row) {
        test2 += "<td>" + lst_row[j] + "</td>"
    }    
    test2 += "</tr>"
}
test2 += "</table>"

return test2;

Which will produce something like this:

and not something like this (which still does not represent something very readable):

To achieve what you are after, you would probably construct the html in the pop-up and fill each field with an expression that would extract the relevant value from the data you have. Not a very elegant solution...

But you can get interesting results as I have shown here: https://community.esri.com/docs/DOC-10692-create-pop-ups-in-arcgis-online-with-conditional-images-us...