HOW TO
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.
Note: To preserve GlobalIDs and avoid the automatic creation of new GlobalIDs, ensure the GlobalID field is already present in the hosted feature layer.
import arcpy file_gdb_path = r"<file_geodatabase_path>" hosted_feature_layer = r"<hosted_feature_layer_URL>"
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, "<field_name>") field1_field_map.outputField.name = "<field_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 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.
Get help from ArcGIS experts
Download the Esri Support App