Hi,
I feel what I am attempting to do is pretty straightforward, but I cannot find an example of it.
I have a related inspections table that I am looking to join to the parent table using a GUID/GLOBALID. From there I want to get a string value from a field (ID) from the parent table record and paste it into any related records in the inspections table.
The code I have accomplishes this (partly) but only for one related record in the inspections table. If there are multiple inspections for that single feature, the remaining related records will have a null value for ID.
Can someone point me the right direction? Thank you!
Here is What I Have so Far:😗
from arcgis import GIS
from arcgis.features import FeatureLayer
import pandas as pd
from datetime import datetime, timedelta
import time
token = GIS(f'')
#INSPECTION TABLE - RELATEDTABLE
inspections_url =''
inspections_lyr = FeatureLayer(inspections_url)
inspections_sdf = pd.DataFrame.spatial.from_layer(inspections_lyr)
inspections_fset = inspections_lyr.query(where="ASSETID=null", out_fields='PARENT_GLOBALID,ASSETID')
inspection_features = inspections_fset.features
#get all inspection features
workOrder_fset = inspections_lyr.query()
all_features = workOrder_fset.features
#MAIN TABLE INFORMATION
valve_url = ''
valve_lyr = FeatureLayer(valve_url)
valve_sdf = pd.DataFrame.spatial.from_layer(valve_lyr)
valve_fset = valve_lyr.query()
valve_features = valve_fset.features
#MERGE TABLES
overlap_rows=pd.merge(left = inspections_sdf, right = valve_sdf, how='inner', left_on='PARENT_GLOBALID',right_on='GlobalID')
valve_updates = valve_fset.features
valve_updates.reverse()
for g in overlap_rows['PARENT_GLOBALID']:
inspection_feature= [f for f in all_features if f.attributes['PARENT_GLOBALID'] == g][0]
valve_feature = [f for f in valve_features if f.attributes['GlobalID'] == g][0]
workOrder_edit = inspection_feature
approval_edit = valve_feature
workOrder_edit.attributes['ASSETID'] = approval_edit.attributes['ASSETID']
workOrder_edit.attributes['TestingField'] = approval_edit.attributes['VALVETYPE']
update_result = inspections_lyr.edit_features(updates=[workOrder_edit])
time.sleep(5)