Hello,
Issue summary: feature_table.edit_features(add=[...]) adds correct number of records but ONLY attributes for single column come through to the hosted feature table. Everything else other than scientificName is blank. My fields are mapped correctly from python dictionary to Hosted Table.
With Python, I am trying to update all records in two AGO Hosted Tables using "feature_table.edit_features(adds=)".
My process is:
[{'attributes': {'lga': 'test',
'scientificName': 'Acacia longifolia',
'classificationLocal': 'Very High Priority',
'localScientific': 'Acacia longifolia'}},
{'attributes': {'lga': 'test',
'scientificName': 'Amaryllis belladonna',
'classificationLocal': 'High Priority',
'localScientific': 'Amaryllis belladonna'}}]
{'addResults': [{'objectId': 1016,
'uniqueId': 1016,
'globalId': '2E655834-2E92-4A57-8F8B-2697122C1DE6',
'success': True},
{'objectId': 1017,
'uniqueId': 1017,
'globalId': 'F09D7D37-98A9-4364-9D9F-35CC8151FA9E',
'success': True}],
'updateResults': [],
'deleteResults': []}
Extra info... Hosted Table fields:
{'OBJECTID': 0, 'scientificName': 1, 'lga': 2, 'classificationLocal': 3, 'localScientific': 4, 'GlobalID': 5}
{'OBJECTID': 0, 'scientificName': 1, 'lga': 2, 'classificationLocal': 3, 'localScientific': 4, 'GlobalID': 5}
{'OBJECTID': 0, 'scientificName': 1, 'commonName': 2, 'wons': 3, 'waStateDeclared': 4, 'qldStateDeclared': 5, 'nswStateDeclared': 6, 'vicStateDeclared': 7, 'saStateDeclared': 8, 'ntStateDeclared': 9, 'GlobalID': 10}
any ideas? I can't figure out what is going wrong here.
Thanks,
Nathan
Hi @nate0102,
Could you post your code? Below is an example I was able to get to work:
from arcgis.gis import GIS
# Variables
username = 'jskinner_rats'
password = '********'
itemID = '5b86f23053fc40aebb7197ce735a4dfc'
# Connect to portal
print("Connecting to AGOL")
gis = GIS("https://www.arcgis.com", username, password)
# Reference Table
print("Referencing table")
fLayer = gis.content.get(itemID)
editTable = fLayer.tables[0]
addFeatures = [
{
'attributes': {
'lga': 'test',
'scientificName': 'Acacia longifolia',
'classificationLocal': 'Very High Priority',
'localScientific': 'Acacia longifolia'
}
},
{
'attributes': {
'lga': 'test',
'scientificName': 'Amaryllis belladonna',
'classificationLocal': 'High Priority',
'localScientific': 'Amaryllis belladonna'
}
}
]
# Add record
print("Adding records")
for record in addFeatures:
editTable.edit_features(adds=[record])
print(result)
print('Finished')
Hi @JakeSkinner, thank you for your response.
I first read in my data from SQL db as a Pandas Dataframe:
Then iterate through the rows to create the list of dictionaries (the edits).
# Prepare the data to be added to the lookup table by iterating through dataframe rows
lookup_lga_class_data = []
for index, row in df_arcade_lookup_lga_class.iterrows():
lookup_lga_class_data.append({
"attributes": {
"lga": row["lga"],
"scientificName": row["scientific_name"],
"classificationLocal": row["classification_local"],
"localScientific": row["local_scientific"]
}
})
lookup_pwd_data = []
for index, row in df_arcade_lookup_pwd.iterrows():
lookup_pwd_data.append({
"attributes": {
"commonName": row["common_name"],
"scientificName": row["scientific_name"],
"wons": row["wons"],
"waStateDeclared": row["wa_state_declared"],
'qldStateDeclared': None,
'nswStateDeclared': None,
'vicStateDeclared': None
}
})
# test to make sure dictionary has populated correctly (it does).
lookup_lga_class_data[:2]
lookup_pwd_data[:2]
# delete the existing features
ft_lookup_lga_class.delete_features(where="1=1")
# add the edits
ft_lookup_pwd.edit_features(adds=lookup_pwd_data)
ft_lookup_lga_class.edit_features(adds=lookup_lga_class_data)
The main difference I can see between our code is that I edit_features in one line by adding the whole list in, instead of a for loop.
Thanks again for your time.
Nathan
Can you post the field overview? Maybe your fields aren't configured as String or they have domains on them?