I have an automated process (using arcpy of course) that will create a service draft and publish a feature class from a gdb successfully. Once the service is up, I can edit existing features and play around with related records in ArcGIS Online and Field Maps. However, when I try to add new features I am unable to because of a default value conflicting with an existing value in the feature class, even though I tried to save with a different value.
I understand that this can be remedied in the feature class' feature template in Desktop as well as Map Viewer Classic, but I am having a couple of issues I was wondering if I could get some help with:
1) According to this link:
https://doc.arcgis.com/en/arcgis-online/manage-data/manage-feature-templates.htm
I should be able to manage feature templates in Map Viewer. But when I try to load a feature service into a map and click on "Edit", the "Manage" button does not appear. I understand that I can only see this button if I am the owner or admin, but I am not clear on what that means. Is the owner the person that published the service or the one that adds it to the map? When I try to set the sharing properties to the admin only and have to log in to view the layer in map viewer, I am still not able to see the "Manage" button. Additionally, adding it to a map in ArcGIS Online Content under a different account does not allow me to see the "Manage" button either.
2) Is there a way to add an empty feature template programatically using arcpy or editing the service somehow?
EDIT: I should also mention that the layer is on one of our ArcGIS Servers and I am adding the layer to the map by using the feature service link. I am also not able to add the feature service to my ArcGIS Online content due to a generic error when trying to add it.
Additionally this service was published on a 10.6.1 server
Solved! Go to Solution.
You can only change templates and types in Map Viewer Classic and Field Maps if the layer is a hosted feature layer. Since your layer is not a hosted feature layer (it's hosted by a separate ArcGIS Server) you cannot change them.
You need to modify the templates in ArcMap or Pro and then re-publish (overwrite) your feature service.
For hosted feature layers, you can script this or make modifications directly at the REST endpoint via updateDefinition. This is not possible for non-hosted feature layers. I'm not sure if you can automate this with arcpy prior to publishing.
You can only change templates and types in Map Viewer Classic and Field Maps if the layer is a hosted feature layer. Since your layer is not a hosted feature layer (it's hosted by a separate ArcGIS Server) you cannot change them.
You need to modify the templates in ArcMap or Pro and then re-publish (overwrite) your feature service.
For hosted feature layers, you can script this or make modifications directly at the REST endpoint via updateDefinition. This is not possible for non-hosted feature layers. I'm not sure if you can automate this with arcpy prior to publishing.
Thanks for the response Aaron. Based on your reply I would think that there is no way to change the service definition to get this working on a non-hosted layer after it has been published?
EDIT: OOPS just saw your mention about not being able to do it on non-hosted layers. Thanks!
Here is how I managed to add a template for anybody wanting to do so with the API: as stated before, you need to do it with updateDefinition (update_definition in python which is what i'm using).
just get your layer or table and:
ud = {
"templates": [{
"name": "new records",
"description": "template desc.",
"prototype": {
"attributes": {
"field_1": 0,
"field_2": 1,
"field_3": "X"
# and so on
}
}
}]
}
result = table.manager.update_definition(ud)
Thanks!
This answer may just save my bacon, but I'm curious, for the prototype part, do you need to include all the attributes of the feature layer or just the attributes that you wish to add with a default value set?
Many thanks!
Haven't played with this in a while, but I would say the only fields that you want with a default. If you have fields defined as not nullable and no default value in prototype and no input value in the form, then it's not going to work (if I remember correctly).
You'll have to do some tests, sorry!
Is this still not possible in Map Viewer?
Providing a way to manage feature templates within Map Viewer is on our future road map. In the mean time, you can use either Map Viewer Classic or the Field Maps Designer app.
I just delt with this issue. The only way I could update templates (add new ones in this case) was by using Map Viewer Classic. You can modify some default values in existing templates and change the display name in Field Maps Designer but you can't create new ones that don't retain at least one field that you can't change.
The Documentation still contains the warning that if you save a map using Map Viewer Classic it will or can break your forms. Is this still true?