HOW TO

Populate a feature layer field based on attributes of another using Arcade in ArcGIS Online

Last Published: February 22, 2024

Summary

In ArcGIS Online, fields in a layer can be populated with attribute values from another feature layer using an Arcade expression. This method is useful in enhancing data integrity and enabling synchronized analysis across layers.

In this article, two feature layers named Cities and ClimateData are used. The Cities feature layer contains two fields named CityAddress and ClimateLocationID. The ClimateData feature layer also contains two fields named ClimateAddress and LocationID. When the CityAddress field values match those of the ClimateAddress, the LocationID values are automatically populated in the ClimateLocationID field.

The images below display the attribute table for both the Cities and ClimateData feature layers.

Attribute table displaying the Cities feature layer
Attribute table displaying the ClimateData feature layer

Procedure

  1. In ArcGIS Online, click the hosted feature layer. On the item details page, click theĀ Data tab.
  2. In the Table view, click the field header and select Calculate. In this example, ClimateLocationID is selected.
  3. In the Calculate Field dialog box, click Arcade.
  4. In the Arcade Calculator dialog box, specify the Expression field as follows:
var <variable1> = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), '<Item_ID>', <layer_index), ['*'], false);
  1. Replace <variable1> with the desired variable name. In this example, climateDataLayer is used.
  2. Replace <Item_ID> with the item ID of the hosted layer.
  3. Replace <layer_index> with either the value 0 or 1. The first layer has an index of 0, while the second layer has an index of 1. In this example, 0 is used as the first layer is to be populated.
var <variable2> = $feature['<field_name1>']; 

for (var<variable3> in <variable1> ) {
 var <variable4> = climateFeature['<field_name2>'];
 
    if <variable2> == <variable4>) {
        return <varibale3>['<field_name3>'];
    }
}

null
  1. Replace <variable2>, <variable3>, and <variable 4> with the desired variable name. In this example, cityAddress, climateFeature and climate Address are used.
  2. Replace <field_name1> with the field name from the first feature layer. In this example, CityAddress is used.
  3. Replace <field_name2> with the field name from the second feature layer. In this example, ClimateAddress is used.
  4. Replace <field_name3> with the field name from the second feature layer to pull the field values. In this example, LocationID is used.

Below is the full working code of the Arcade expression.

var climateDataLayer = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'fd3161f30d6f47aba8b58f6fcb5ed488', 0, ['*'], false);

var cityAddress = $feature['CityAddress']; 

for (var climateFeature in climateDataLayer) {
    var climateAddress = climateFeature['ClimateAddress'];

    if (cityAddress == climateAddress) {
        return climateFeature['LocationID']; 
    }
}

null
  1. Click Test to verify the expression, and click OK to apply the query.
Arcade expression configuration.jpg

The attribute table below displays the ClimateLocationID field of the Cities feature layer populated with values from the LocationID field of the ClimateData feature layer when the CityAddress field values match the ClimateAddress.

ClimateLocationID field populated by the values of the LocationID field.png

Article ID: 000031934

Software:
  • ArcGIS Online

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options