HOW TO
Arcade expressions provide the ability to calculate new fields with values from available attribute data in the feature layers in ArcGIS Online. In some cases, it is necessary to populate a new field with values based on substring values from another field. For example, when inspecting fire hydrants in a city, the area codes for the fire hydrants are determined based on the their unique ID (for example, X-100B with '-1' represents the area code 'A'). This article describes the workflow to add a new field and populate it with area codes for each fire hydrant using its ID.
The following image shows the attribute table of the fire hydrants ID field, and the new field to be populated with area codes.
if (Find("-1", $feature.ID, 0)>0) { return "A"; } else if (Find("-2", $feature.ID, 0)>0) { return "B"; } else if(Find("-3", $feature.ID, 0)>0) { return "C"; } else if(Find("-4", $feature.ID, 0)>0) { return "D"; } else if(Find("-5", $feature.ID, 0)>0) { return "E" }
Note: The following explains the components of the expressions: Find("-1", $feature.ID, 0)>0) The 'Find' function searches through the ID field, and if '-1' exists, it returns '1'. Otherwise, it returns '0'. if (Find("-1", $feature.ID, 0)>0) { return "A"; The 'if' statement specifies a condition that if '-1' exists in the ID field, the condition is true, so the new field is populated with A. } else if (Find("-2", $feature.ID, 0)>0) { return "B"; The 'else if' statement specifies a new true condition. Since '-2' exists in the ID field, the new field is populated with B.
The image below shows the Area_Code field populated with values calculated using Arcade expressions.
Get help from ArcGIS experts
Download the Esri Support App