Arcade - how calculate Field in FeatureSet

227
2
Jump to solution
11-26-2021 11:20 AM
Labels (1)
VHolubec
Esri Regular Contributor

Hello,

I am trying to get work an Arcade expression to create a FeatureSet, which I want to use then for Serial chart.
In simplification, I am taking an attribute ZONE from the layer:


var fs = FeatureSetByPortalItem(Portal('https://arcgis.com'),'e7ad315d17a742fda44fb63cd311152a',0,['ZONE'], false)

The ZONE attribute is a string which looks like P6-0176. The goal is to create a field in the FeatureSet which recalculate the ZONE filed but keeps the first two chars only - so the result for this example would be P6.

So I am creating a new FeatureSet definition, and the attribute ZONE I would like to use in LEFT function.
But if I use the code like this:

var novy = {
'fields': [{'name':'Zona', 'type':'esriFieldTypeString'}],
'geometryType': '',
'features':
[{'attributes':
{'Zona': Left((fs,'ZONE'), 2)
}}]};
return FeatureSet(Text(novy))

The result is the error for the LEFT function.

 

What is the correct syntax to call the column ZONE from the original FeatureSet FS in the LEFT function? Or is there any other way (and this is not the correct one) how to recalculate the ZONE attribute in original FeatureSet FS.

Thank you for any ideas

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
Regular Contributor

To insert code:

JohannesLindner_0-1638260465949.png

JohannesLindner_1-1638260485929.png

 

You are trying to input a tuple of (FeatureSet, Text) into the Left function, which is not a valid argument.

According to the docs, the first argument can be Text, Array, Number, or Boolean.

You have to fill your feature set sequencially:

var fs = FeatureSetByPortalItem(Portal('https://arcgis.com'),'e7ad315d17a742fda44fb63cd311152a', 0, ['ZONE'], false)

var novy = {
  'fields': [{'name':'Zona', 'type':'esriFieldTypeString'}],
  'geometryType': '',
  'features': []
}
for(var f in fs) {
  var new_f = {'attributes': {'Zona': Left(f.ZONE, 2)}}
  Push(novy.features, new_f)
}
return FeatureSet(Text(novy))

 


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
Regular Contributor

To insert code:

JohannesLindner_0-1638260465949.png

JohannesLindner_1-1638260485929.png

 

You are trying to input a tuple of (FeatureSet, Text) into the Left function, which is not a valid argument.

According to the docs, the first argument can be Text, Array, Number, or Boolean.

You have to fill your feature set sequencially:

var fs = FeatureSetByPortalItem(Portal('https://arcgis.com'),'e7ad315d17a742fda44fb63cd311152a', 0, ['ZONE'], false)

var novy = {
  'fields': [{'name':'Zona', 'type':'esriFieldTypeString'}],
  'geometryType': '',
  'features': []
}
for(var f in fs) {
  var new_f = {'attributes': {'Zona': Left(f.ZONE, 2)}}
  Push(novy.features, new_f)
}
return FeatureSet(Text(novy))

 


Have a great day!
Johannes
VHolubec
Esri Regular Contributor

Thank you very much @JohannesLindner, it works great!

0 Kudos