Arcade - Replacing null values with a custom value within a dictionnary

143
2
Jump to solution
2 weeks ago
RemyOlive
New Contributor II

Hello everyone,

I'm very new to Arcade, and am working to populate an indicator from multiple feature layers.

My problem is that I have a value, called "ArrivalTime" (which is a number) that some layers have, and others don't. When I execute the code, the layers that do not have an "ArrivalTime" show this value as "null" and I cannot filter based on it, they just get excluded automatically.

My question is, I'd like to replace this "null" value by a 0, so that I can filter on them the same as the layers that do have an "ArrivalTime" value.

var Length_Canada = FeatureSetByPortalItem(port, '5ae0748d2b454853bcf47bffc3245a39', 12, ['*'], true)
var Length_Australia = FeatureSetByPortalItem(port, '44708b8c1c2f4338835e51baee64d1a9', 9, ['*'], true)

Console(Length_Australia)
Console(Length_Canada)
var combinedDict = { 
  'fields': [ 
    { name: "Shape_Length", type:"esriFieldTypeDouble" },
    { name: "ArrivalTime", type:"esriFieldTypeDouble" },
  ], 
  geometryType: "esriGeometryPolyline", 
  features: [], 
}; var i = 0; 

for (var t in Length_Canada) { 
  combinedDict.features[i++] = { 
    attributes: {
      Shape_Length: t["Shape__Length"],
      Arrival_Time: "0"
    }, 
    geometry: Geometry(t)
  }; 
} for (var m in Length_Australia) { 
  combinedDict.features[i++] = { 
    attributes: { 
      Shape_Length: m["Shape__Length"],
      ArrivalTime: m["ArrivalTime"]
    }, 
    geometry: Geometry(m)
  }; 
}
return FeatureSet(combinedDict)

Here is the code, as the Canada layers do not have any "ArrivalTime" value, I'm trying to force a 0 as the default value (line 19), but it keeps on returning a null value.

RemyOlive_0-1714478055522.png

Here is an example of the return table that I get.

Any help would be appreciated,

Thanks a lot,

Rémy 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

The dictionary contained the field "ArrivalTime" but you were assigning 0 to "Arrival_Time".

for (var t in Length_Canada) { 
  combinedDict.features[i++] = { 
    attributes: {
      Shape_Length: t["Shape__Length"],
      ArrivalTime: 0
    }, 
    geometry: Geometry(t)
  }; 
} 

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

The dictionary contained the field "ArrivalTime" but you were assigning 0 to "Arrival_Time".

for (var t in Length_Canada) { 
  combinedDict.features[i++] = { 
    attributes: {
      Shape_Length: t["Shape__Length"],
      ArrivalTime: 0
    }, 
    geometry: Geometry(t)
  }; 
} 
0 Kudos
RemyOlive
New Contributor II

Oh right it works now,

Thank you so much !! Why couldn't I have seen that earlier,

Cheers,

Rémy

0 Kudos