|
POST
|
I'm a lot closer now after making quite a few changes. Now I'm getting the error message: A general error occurred: Circular reference detected
ERROR: A general error occurred: Circular reference detected I believe that the error is in line 42. I replaced some info with ... for security purposes. from arcgis.gis import GIS
gis = GIS("home")
# Import arcpy module
from arcgis.gis import GIS
from arcgis.features import FeatureLayer, GeoAccessor # might not need that last one?
import time, arcpy, os, datetime
# Variables
s123Layer = r'https://services.arcgis.com/.../FeatureServer/0'
report_copy_url = r'https://services.arcgis.com/.../FeatureServer/0'
try:
item = gis.content.get("...")
feature_layer = item.layers[0]
field_name = "ReportDate"
query_result = feature_layer.query(out_statistics=[{"statisticType": "max", "onStatisticField": field_name}])
milliseconds = query_result.features[0].attributes[f"MAX_{field_name}"]
date_time = datetime.datetime.utcfromtimestamp(milliseconds / 1000.0)
max_date = date_time.strftime('%Y-%m-%d %H:%M:%S')
print("Most recent report date in ...:", max_date)
feature_layer = FeatureLayer(s123Layer, gis=gis)
query = f"submission_date_and_time > timestamp '{max_date}'"
selected_features = feature_layer.query(where=query)
print(f"Number of new features to append to ...: {len(selected_features)}")
###### SCRIPT WORKS TO THIS POINT #######
if len(selected_features.features)>0:
fm = [{'ObservationDate':'ReportObservationDate',
'CampsiteDescription':'ReportCampsiteDescription',
'FollowUpRequest':'ReportFollowUpRequest',
'SubmitterName':'ReportSubmitterName',
'PreferredContact':'ReportSubmitterPreferredContact',
'EmailAddress':'ReportSubmitterEmailAddress',
'PhoneNumber':'ReportSubmitterPhoneNumber',
'submission_date_and_time':'ReportDate'
}]
targetLayer = FeatureLayer(report_copy_url,gis=gis)
targetLayer.append(selected_features.features, field_mappings = fm, return_messages = True)
else:
print("No new reports to load into ...")
except Exception as e:
print(e)
arcpy.AddError(str(e)) @JakeSkinner @Clubdebambos - do you see any issues?
... View more
12-04-2024
01:19 PM
|
0
|
0
|
973
|
|
POST
|
Thank you! That worked for error trapping. I fixed the issue, but field mapping doesn't work. if len(selected_features.features)>0:
field_mapping = {'ObservationDate':'ReportObservationDate',
'CampsiteDescription':'ReportCampsiteDescription',
'FollowUpRequest':'ReportFollowUpRequest',
'SubmitterName':'ReportSubmitterName',
'PreferredContact':'ReportSubmitterPreferredContact',
'EmailAddress':'ReportSubmitterEmailAddress',
'PhoneNumber':'ReportSubmitterPhoneNumber',
'submission_date_and_time':'ReportDate'
}
sdf = feature_layer.query(where=query)
feature_layer.edit_features(adds = sdf, field_mapping=field_mapping) Line 12 generates the error: FeatureLayer.edit_features() got an unexpected keyword argument 'field_mapping'
ERROR: FeatureLayer.edit_features() got an unexpected keyword argument 'field_mapping' I tried using field_mappings (plural) since that's listed in the FeatureLayer append method as a keyword, but no luck. So then I thought I'd try the append method, but I'm getting Unknown Error (Error Code: 500) in response to this: if len(selected_features.features)>0:
field_mapping = [{'ObservationDate':'ReportObservationDate',
'CampsiteDescription':'ReportCampsiteDescription',
'FollowUpRequest':'ReportFollowUpRequest',
'SubmitterName':'ReportSubmitterName',
'PreferredContact':'ReportSubmitterPreferredContact',
'EmailAddress':'ReportSubmitterEmailAddress',
'PhoneNumber':'ReportSubmitterPhoneNumber',
'submission_date_and_time':'ReportDate'
}]
sdf = feature_layer.query(where=query)
feature_layer.append(sdf,
field_mappings = field_mapping,
return_messages = True) My guess is that the error code is the result of not specifying an item_id, since sdf is a selection of records and not an entire item. Any ideas on what to try next? I wish the ArcGIS API for Python documentation consistently provided sample code like the arcpy documentation does.
... View more
11-21-2024
08:25 AM
|
0
|
0
|
2769
|
|
POST
|
Just for clarification, I do have the variable feature_layer defined earlier in the script and it's working properly. item = gis.content.get("999999999") # actual item id has been removed for this chat
feature_layer = item.layers[0]
... View more
11-19-2024
02:28 PM
|
0
|
1
|
2782
|
|
POST
|
I still have something wrong, but I don't know how to print error messages because arcpy.GetMessages() doesn't return anything. Is there another way to get the error messages from failed functions? Here's the portion of code that is failing: field_mapping = {'ObservationDate':'ReportObservationDate',
'CampsiteDescription':'ReportCampsiteDescription',
'FollowUpRequest':'ReportFollowUpRequest',
'SubmitterName':'ReportSubmitterName',
'PreferredContact':'ReportSubmitterPreferredContact',
'EmailAddress':'ReportSubmitterEmailAddress',
'PhoneNumber':'ReportSubmitterPhoneNumber',
'submission_date_and_time':'ReportDate'
}
sdf = feature_layer.query(where=query).sdf
feature_layer.edit_features(adds = sdf.to_featureset(), field_mapping=field_mapping) I think line 10 is working because I added a print statement for the sdf variable and got this (confidential information blurred in the screenshot):
... View more
11-19-2024
02:26 PM
|
0
|
0
|
2782
|
|
IDEA
|
In Portal 11.3, we have a web map that is shared with four groups that limit access to people who are trained in editing. We added two web layers to this map that are shared with Organization. When we tried to save the web map, we were prevented from doing so because the layers were not explicitly shared with the same groups as the web map. My suggestion is that Portal should consider items shared with an entire organization as equivalent to being shared with groups. For clarity, we do not want to share these layers with Everyone (e.g. make them public).
... View more
11-19-2024
07:05 AM
|
3
|
1
|
551
|
|
POST
|
I don't have any attachments, @Clubdebambos. Is there a way to do field mapping with the edit_features function? Some of the field names in the input feature layer don't match the target layer.
... View more
11-13-2024
07:25 AM
|
0
|
2
|
2841
|
|
POST
|
I'm new to using the ArcGIS API for Python in an ArcGIS Online Notebook and am looking for help to identify the right function(s) for a data maintenance script I'm migrating from a scheduled task on a server. The start of the script works fine: I select a small number of records from a hosted feature layer. (If it matters, the hosted feature layer is part of a Survey123 survey). I'm struggling with finding the function(s) to: 1. Append those selected records to another hosted feature layer, and 2. On those newly appended records, update the value in the status field to 'Not Reviewed'. The status field does not exist in the source layer, but it does in the target layer. These two steps don't have to be in this order. I'm fine with exporting the records, adding a status field, calculating that 'Not Reviewed' value and then appending the updated records to my target layer. Appreciate any hints that the community can offer!
... View more
11-12-2024
08:39 AM
|
0
|
13
|
3877
|
|
IDEA
|
To add to this excellent idea, the workaround that GT_UTCO offers does not work for users who use IWA SAML to authenticate. I cannot use the SignInToPortal function to force a switch of portals because storing the username and password in the script does not work for IWA (using Active Directory credentials to log in). At this point, my only workaround is to use a Notebook for my all-ArcGIS Online script and leave my portal default on our Enterprise Portal for our other scripts. This breaks our organization's governance guidelines because we don't allow individuals to own maintenance scripts so that scripts stop working when a person leaves the company. Edited to add: I made a mistake in this original post. We use SAML authentication, not IWA.
... View more
11-05-2024
06:41 AM
|
0
|
0
|
1420
|
|
POST
|
@RhettZufelt - regarding "I have a scheduled task that opens/closes Pro every monday night just to keep my sign in active." Can you provide details on this? I've been digging through the arcpy documentation without luck to find a function that will do this because I'm having issues with my account logging out of its connection to our Portal, presumably due to inactivity.
... View more
11-04-2024
10:25 AM
|
0
|
1
|
3973
|
|
POST
|
You hit the nail on the head. I forgot that I changed my default portal to our Enterprise Portal to support some new scripts that I took ownership of from a departing employee. I'll need to find a way to change portals in my scripts to address that issue. Thank you!
... View more
10-31-2024
06:27 AM
|
0
|
0
|
1125
|
|
POST
|
I have a line at the beginning of a script that reads as follows: item = gis.content.get("03e43ce195534e028e7bf49e951414c8") I know that the item ID is valid for a hosted feature layer in my ArcGIS Online organization and that the log-in that I'm using to run the script has permission to access it. (It is not shared publicly, so even if you search for it on your own, you won't be able to view it.) If I add the following statement to the script... print(item) ... the print statement returns "None". Based on this post, a return of "None" means that the feature layer has a size of zero bytes. This isn't possible, as the layer has 502 records. The subsequent steps involve reading through a specific field to look for the most recent date, but the script doesn't get to that point because the get.content.get step isn't returning data. Any ideas for troubleshooting?
... View more
10-30-2024
07:37 AM
|
0
|
2
|
1163
|
|
POST
|
Here's another issue that I ran into today. I have a user named gis_viewer in our SQL database that I was using to connect to the enterprise database with my data. I can publish services to Portal with that database connection, but it's missing a permission that will prevent the data from copying via the collaboration. I don't know what the permission is, but I think it requires more than SELECT. Maybe someone from Esri like @ReeseFacendini can provide the link to that resource?
... View more
08-20-2024
01:12 PM
|
0
|
0
|
5863
|
|
POST
|
There is a bug in Enterprise 11.1 for multi-machine deployments that is fixed in 11.3: 113-IssuesAddressedList_06112024.pdf (esri.com) In addition to edit sync failures, I was getting a lot of those generic "failed to export item" errors while still on Enterprise 11.1. Upgrading to 11.3 resolved my issue. One other thing to check: make sure that you aren't hiding any fields in your attribute table. In particular, the sync needs all of the editor tracking fields as well as global ID. I got that generic error many times when I had hidden those fields from the attribute table before publishing to Portal. Good luck!
... View more
08-20-2024
10:50 AM
|
3
|
2
|
5887
|
|
POST
|
I don't have a solution or explanation yet, but I do have a workaround. After adding the new layer to a web map, I removed the unique symbology and the redid it from scratch. Somehow, making any change to the symbology resolves the issue. All I can guess right now is that the web map or the Instant App doesn't like something about the symbology as-is when it comes across in the collaboration. I've got a ticket in with Esri tech support, but I'm really not sure whether we'll find a root cause or not. It was a pain to manually redo the colors on 20 bus routes, but hey, if it works, it works!
... View more
08-16-2024
02:20 PM
|
0
|
0
|
1195
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 12-16-2021 07:17 AM | |
| 6 | 3 weeks ago | |
| 1 | 06-27-2024 01:11 PM | |
| 1 | 07-15-2021 01:53 PM | |
| 2 | 01-09-2026 07:45 AM |
| Online Status |
Offline
|
| Date Last Visited |
3 weeks ago
|