Esri / ArcREST

python package for REST API (AGS, AGOL, webmap JSON, etc..)
Apache License 2.0
192 stars 155 forks source link

ArcRest "FieldToAdd" Does Not Appear to be Working? #329

Open jocktheshockerrr opened 7 years ago

jocktheshockerrr commented 7 years ago

ArcRest

3.5.9

Version or date of download

Bug or Enhancement

Repo Steps or Enhancement details

I do not have any error messages, however when I check the service, nothing has been added - I am very new to this so please forgive me, if this seems poorly constructed.

Code: """ Adds a field to any layer matching the name in all feature services without republishing """ import arcrest

 if __name__ == "__main__":
  url = "https://services7.arcgis.com/pKZDS1XjUiThltHY/arcgis/rest/admin/services/BuildingsService/FeatureServer"
  username = "Name"
  password = "Pass"
  featureLayerNames = ["BuildingsShapes"]
  fieldToAdd = {

    "fields" : [
        {
            "name" : "CommonField3",
            "type" : "esriFieldTypeString",
            "alias" : "Common Field 2",
            "sqlType" : "sqlTypeOther", "length" : 50,
            "nullable" : True,
            "editable" : True,
            "domain" : None,
            "defaultValue" : None
        }  ]
}
  sh = arcrest.AGOLTokenSecurityHandler(username, password)
  agolServices = arcrest.hostedservice.Services(url, securityHandler=sh)
  for service in agolServices.services:
      if not service.layers is None:
          print service.url
          for lyr in service.layers:
              print lyr.name    

              if lyr.name.lower() in featureLayerNames:
                  print lyr.addToDefinition(fieldToAdd)                    
                  #  Output: {'success': True}