I was able to create a When() statement in Arcade for the ArcGIS Online pop-up of a Work Order hosted feature class that displays the workers' names without the underscore in the name and puts each new name on a separate line. I am trying to recreate this in Dashboard, since Arcade cannot be done in Experience Builder Lists. However, the syntax is different when doing the code for pop-ups versus in the Dashboard List. Can someone please help me determine how to do it, if possible? The current setup looks something like this:
var worker = $feature["WORKERS_ASSIGNED"]
When(
worker == 'Worker_One',"Worker One",
worker == 'Worker_Two',"Worker Two",
worker == 'Worker_Three',"Worker Three",
"Unknown")
Depending on which worker(s) are chosen, the names show up in the pop-up as:
Worker One
Worker Two
Worker Three
My reasoning for doing this is so the names look nicely formatted in the app List (whether in Dashboard or Experience Builder), instead of having a list like Worker_One,Worker_Two,Worker_Three. I currently have a field for each worker name (~25) that formats the name in Survey123 Connect, but I'd love to be able to get rid of those extra fields. This is the only way I've found that might allow me to do this. Any advice is welcome!
To post code:
However, the syntax is different when doing the code for pop-ups versus in the Dashboard List
The main difference is that you have to return a Featureset for Dashboard elements.
Let me start by saying this: If all you're doing is removing the underscores, you're making it much too complicated. Your popup expression could look like this:
// replace underscore with space
return Replace($feature["WORKERS_ASSIGNED"], "_", " ")
Now, a data expression that goes through your Survey layer and replaces the underscores in the WORKERS_ASSIGNED field could look like this:
// this is my test data
//var fs = {geometryType:"",fields:[{name:"WORKERS_ASSIGNED",type:"esriFieldTypeString"}, {name:"X",type:"esriFieldTypeInteger"}],features:[{attributes:{WORKERS_ASSIGNED:"Joe_Biden", X:46}},{attributes:{WORKERS_ASSIGNED:"Donald_Trump", X:45}},{attributes:{WORKERS_ASSIGNED:"Barack_Obama", X:44}},{attributes:{WORKERS_ASSIGNED:"George_W_Bush", X:43}},{attributes:{WORKERS_ASSIGNED:"Bill_Clinton", X:42}},{attributes:{WORKERS_ASSIGNED:"George_H_W_Bush", X:41}},{attributes:{WORKERS_ASSIGNED:"Ronald_Reagan", X:40}}]}
//fs = Featureset(Text(fs))
// load your Layer
var fs = FeaturesetByPortalItem(...)
// Copy the schema of your layer into a new emppty Featureset
var fs_schema = Schema(fs)
var out_fs = {
geometryType: fs_schema.geometryType,
fields: fs_schema.fields,
features: []
}
// loop over your Layer's features
for(var f in fs) {
// get the attributes
var att = Dictionary(Text(f)).attributes
// replace underscores
att.WORKERS_ASSIGNED = Replace(att.WORKERS_ASSIGNED, "_", " ")
// append the edited feature to the output featureset
Push(out_fs.features, {geometry: Geometry(f), attributes: att})
}
// return the output featureset
return Featureset(Text(out_fs))
Be sure that you actually load your Layer in line 6. Using the FeaturesetByPortalItem function, you also can limit the fields you want to import.
This is my test input
And the output it created