Select to view content in your preferred language

Migrating Feature Layer with both photos and related table from ArcGIS Pro to FieldMaps

73
1
yesterday
MegRFay
Occasional Contributor

Hi all! I recently inherited a Field Maps tool made by a consultant to inventory bus stops. Now that the project is complete, people are looking to create a new Field Maps tool where we can open work tickets. 

I have created a replica of the feature layer as a file gdb and opened in arcgis pro. I want to make a copy of the main point layer, make some changes, reattach the photos, and create a new 1:M related table attachment for work tickets. And then use this in a new tool where the form will be used to create and close tickets, while being able to view the data and photos (and maybe add new photos). 

I am new to field maps, but I have some parts of this project working just fine (like creating the work tickets and filling them out in Field Maps), but cannot seem to get the photos. The Attachment field is there in the new online feature layer, but shows zero attachments. I feel like I am missing a step, or doing these steps in the wrong order. I have attached the code I am using the hopefully get the photos back onto the data after making a copy and adding/removing some fields. I have also attached a screenshot of the feature class before making a web layer that shows there are attachments. 

MegRFay_0-1765998672714.png

 



import arcpy
import os

# -------------------------------------------------------------------
# INPUTS
# -------------------------------------------------------------------

gdb_path = r"C:/Users/mfay/data/17f2dd9e-0f63-41aa-abda-ff44e9fe67bb.gdb"

input_fc = os.path.join(gdb_path, "Stops_v5_property")
output_fc = os.path.join(gdb_path, "Stops_base")

workspace = os.path.dirname(output_fc)
arcpy.env.workspace = workspace

# -------------------------------------------------------------------
# Build the attachment table and relationship class names
# -------------------------------------------------------------------
input_attach = input_fc + "__ATTACH"
input_rel = input_fc + "__ATTACHREL"

output_attach = output_fc + "__ATTACH"
output_rel = output_fc + "__ATTACHREL"

# -------------------------------------------------------------------
# 1. Enable attachments on the output FC (creates ATTACH + REL tables)
# -------------------------------------------------------------------
print("Enabling attachments on output feature class...")
arcpy.management.EnableAttachments(output_fc)

# -------------------------------------------------------------------
# 2. Append attachment records
# -------------------------------------------------------------------
print("Appending attachments...")
arcpy.Append_management(inputs=input_attach, target=output_attach, schema_type="NO_TEST")

# -------------------------------------------------------------------
# 3. Verify attachment counts
# -------------------------------------------------------------------
def count_attachments(attach_table):
    """Return number of attachment records."""
    if arcpy.Exists(attach_table):
        return int(arcpy.GetCount_management(attach_table)[0])
    return 0

input_count = count_attachments(input_attach)
output_count = count_attachments(output_attach)

print("\n-------------------- Attachment Verification --------------------")
print(f"Input attachment count:  {input_count}")
print(f"Output attachment count: {output_count}")

if output_count == input_count:
    print("✔ Attachment counts match — SUCCESS.")
else:
    print("⚠ WARNING: Attachment counts do NOT match!")

print("-----------------------------------------------------------------")
print("Process complete.")

 

0 Kudos
1 Reply
RhettZufelt
MVP Notable Contributor

I believe by default, arcpy.Append_management does not include attachments.

Try adding arcpy.env.maintainAttachments = True before you run the append.

R_

0 Kudos