3

We have a fields in a large amount of AGOL hosted feature layers that we want to make un-editable and others that we do not want visible.

Rather than going into the service definition for each and every one to manually change "editable": true to "editable": false for many fields in many feature layers, and then also do the same for "visible", we were hoping to automate the process via the Python API (which we are new to).

So far we have:

from arcgis.gis import gis
gis = GIS(.....login info......)
mpfs = gis.content.get(......id......)
mpfl = mpfs.layers[0]
replacementCopy = mpfl.properties.fields
for field in replacementCopy:
    if field.name in (list of names):
        field["editable"] = False
for field in replacementCopy:
    if field.name in (list of names):
        field["visible"] = False

But the field properties seem to be missing the "visible" property, and we are not sure how to go about enacting the changes once we have the update field properties.

1

Hosted Feature Layers do not have a 'visible' property according to the REST API. Here are the properties you should expect to see at 10.6.1:

"fields" : [
 {
  "name": "<fieldName1>", "type": "<fieldType1>", 
  "alias": "<fieldAlias1>", "domain": <domain1>, 
  "editable": "<true | false>", "nullable": "<true | false>", 
  "length": "<length1>", "defaultValue": "<defaultValue1>",
  "modelName": "<modelName1>"
 }

In regard to how to update, the Python API has a limited number of properties that can be accessed. It seems to only be focused on layer-level metadata, like Name/Description/etc. See available properties available for update:

https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.gis.toc.html?highlight=update#arcgis.gis.Item.update

| improve this answer | |
  • So is there a way to automate updating Layer Definitions? Also when going to the Update Layer Definition page via AGOL I see: "fields" : [ { "name": "<fieldName1>", "type": "<fieldType1>", "alias": "<fieldAlias1>", "sqlType": sqlTypeOther, "domain": <domain1>, "editable": "<true | false>", "nullable": "<true | false>", "visible": "<length1>", "defaultValue": "<defaultValue1>" } – jtmouw Aug 24 '18 at 11:44
  • You can use several libraries for javascript or python to form custom REST posts. See: esri.github.io/arcgis-rest-js/api/request/request enterprise.arcgis.com/en/server/latest/administer/windows/… – psl Aug 27 '18 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.