HOW TO

Preserve Global IDs when appending features from a file geodatabase to a hosted feature layer in ArcGIS Online

Last Published: September 30, 2024

Summary

Sometimes, the Global ID field is not preserved when appending features from a file geodatabase to a hosted feature layer in ArcGIS Online. Preserving Global IDs is crucial, as they uniquely identify each feature and are often used to track relationships, sync data, and manage editing history, particularly in offline workflows and feature services.

This article provides a workflow for appending a file geodatabase to a hosted feature layer in ArcGIS Online using a Python script run in the Python window within ArcGIS Pro.

Procedure

  1. Open the project in ArcGIS Pro.
  2. Open the Python window. Refer to ArcGIS Pro: Python window for more information.
Note:
To preserve GlobalIDs and avoid the automatic creation of new GlobalIDs, ensure the GlobalID field is already present in the hosted feature layer.
  1. Run the following script:
    1. Define paths to the input file geodatabase and the target hosted feature layer.
import arcpy 

file_gdb_path = r"<file_geodatabase_path>"
hosted_feature_layer = r"<hosted_feature_layer_URL>"
    1. Create a FieldMappings object. This object defines how the fields from the source (file geodatabase) are mapped to the target (hosted feature layer).
field_mappings = arcpy.FieldMappings()
    1. Create a FieldMap object for the Global ID field and set the output field properties for the GlobalID field.
global_id_field_map = arcpy.FieldMap()
global_id_field_map.addInputField(file_gdb_path, "GlobalID")
global_id_field_map.outputField.name = "GlobalID"
    1. Add the field map for Global ID to the FieldMappings object.
field_mappings.addFieldMap(global_id_field_map)
    1. Add field maps for other fields if needed. Replace <field_name> with the name of the field to be mapped.
field1_field_map = arcpy.FieldMap()
field1_field_map.addInputField(file_gdb_path, "<field_name>")
field1_field_map.outputField.name = "<field_name>"
field_mappings.addFieldMap(field1_field_map)
    1. Append the features to the hosted feature layer.
arcpy.Append_management(file_gdb_path, hosted_feature_layer, schema_type="NO_TEST", field_mapping=field_mappings)

The code block below demonstrates the full working script.

import arcpy

file_gdb_path = r"C:\Users\dpalzaniappan\Documents\ArcGIS\Projects\MyProject91\MyProject91.gdb\Testi"
hosted_feature_layer = r"https://services9.arcgis.com/LMjydzYxR6YFiqk8/arcgis/rest/services/Testio123/FeatureServer/0"

field_mappings = arcpy.FieldMappings()

global_id_field_map = arcpy.FieldMap()
global_id_field_map.addInputField(file_gdb_path, "GlobalID")
global_id_field_map.outputField.name = "GlobalID"

field_mappings.addFieldMap(global_id_field_map)

field1_field_map = arcpy.FieldMap()
field1_field_map.addInputField(file_gdb_path, "Name")
field1_field_map.outputField.name = "Name"
field_mappings.addFieldMap(field1_field_map)

arcpy.Append_management(file_gdb_path, hosted_feature_layer, schema_type="NO_TEST", field_mapping=field_mappings)

The image below displays the Python script used in the Python window in ArcGIS Pro to append the file geodatabase to the hosted feature layer.

The Python script in the Python window

Article ID: 000032358

Software:
  • ArcGIS Online
  • ArcGIS Pro 3 1
  • ArcGIS Pro 3 3
  • ArcGIS Pro 3 2

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

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options