<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to add a new field to a Hosted Feature Layer? in ArcGIS Notebooks Questions</title>
    <link>https://community.esri.com/t5/arcgis-notebooks-questions/how-to-add-a-new-field-to-a-hosted-feature-layer/m-p/1034435#M258</link>
    <description>&lt;P&gt;&lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.managers.html#arcgis.features.managers.FeatureLayerManager.add_to_definition" target="_self"&gt;Using a feature layer manager&lt;/A&gt; via Python, as&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/417320"&gt;@Damian&lt;/a&gt; shows, is certainly one way to do it, and a method that I use often myself. However, there's no limitation on the &lt;STRONG&gt;arcpy.management.AddField() &lt;/STRONG&gt;function that would prevent you from using it against a hosted feature layer. I've tested it, and it works just fine.&lt;/P&gt;&lt;P&gt;This issue, I think, stems from attempting to use the function from a &lt;EM&gt;notebook&lt;/EM&gt;. Using a standard notebook in AGOL, try running &lt;EM&gt;any&lt;/EM&gt; arcpy function and you'll get an error, because arcpy is not an available module in the standard AGOL Notebook environment.&lt;/P&gt;&lt;P&gt;I tried opening your notebook link, but it doesn't show anything. Can you confirm which type of notebook you've got? You can see &lt;A href="https://doc.arcgis.com/en/arcgis-online/reference/use-arcpy-in-your-notebook.htm" target="_self"&gt;in the AGOL docs&lt;/A&gt; that ArcPy &lt;EM&gt;is&lt;/EM&gt; available, but only by using the advanced notebook runtimes. That would be my first guess.&lt;/P&gt;&lt;P&gt;Also, if the notebook still exists, make sure it's public so that others can see the preview page.&lt;/P&gt;</description>
    <pubDate>Tue, 09 Mar 2021 14:19:29 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2021-03-09T14:19:29Z</dc:date>
    <item>
      <title>How to add a new field to a Hosted Feature Layer?</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/how-to-add-a-new-field-to-a-hosted-feature-layer/m-p/227352#M36</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&amp;nbsp;I am trying to add a &lt;EM&gt;new&lt;/EM&gt; field to a &lt;A href="https://cerebellum.maps.arcgis.com/home/item.html?id=e52a0f35741e4eb0b87f8f1f499f26be"&gt;Feature Layer (hosted)&lt;/A&gt;.&amp;nbsp; I thought that I could call the &lt;A href="https://pro.arcgis.com/en/pro-app/tool-reference/data-management/add-field.htm"&gt;Add Field&lt;/A&gt;&amp;nbsp;function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Am I not passing in the correct parameters?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my Notebook link (below):&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.arcgis.com/home/item.html?id=13fbc9ff800c4ea8b118b7ce270759ef#preview"&gt;Notebook Preview&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code snippet:&lt;/P&gt;&lt;PRE style="color: #333333; background-color: #f7f7f7; border: none; font-size: 14px;"&gt;&lt;SPAN class="" style="color: #408080;"&gt;# Item: Salzburg Austria Feature Layer&lt;/SPAN&gt;&lt;SPAN class=""&gt;input_data&lt;/SPAN&gt; &lt;SPAN class="" style="color: #666666;"&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;gis&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;content&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;get&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #ba2121;"&gt;"e52a0f35741e4eb0b87f8f1f499f26be"&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #408080;"&gt;# Item's layer&lt;/SPAN&gt;&lt;SPAN class="" style="color: #008000;"&gt;type&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;input_data&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;layers&lt;/SPAN&gt;&lt;SPAN class=""&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;0&lt;/SPAN&gt;&lt;SPAN class=""&gt;])&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="color: #333333; background-color: #f7f7f7; border: none; font-size: 14px;"&gt;&lt;SPAN class="" style="color: #008000; font-weight: bold;"&gt;try&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;    &lt;SPAN class=""&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;AddField_management&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;in_table&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;=&lt;/SPAN&gt;&lt;SPAN class=""&gt;input_data&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;layers&lt;/SPAN&gt;&lt;SPAN class=""&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;0&lt;/SPAN&gt;&lt;SPAN class=""&gt;],&lt;/SPAN&gt;                                &lt;SPAN class=""&gt;field_name&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #ba2121;"&gt;"Description"&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;                                &lt;SPAN class=""&gt;field_type&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #ba2121;"&gt;"TEXT"&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;                                &lt;SPAN class=""&gt;field_precision&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #ba2121;"&gt;""&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;                                &lt;SPAN class=""&gt;field_scale&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #ba2121;"&gt;""&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;                                &lt;SPAN class=""&gt;field_length&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #ba2121;"&gt;"50000"&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;                                &lt;SPAN class=""&gt;field_alias&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #ba2121;"&gt;""&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #008000; font-weight: bold;"&gt;except&lt;/SPAN&gt; &lt;SPAN class=""&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;ExecuteWarning&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;    &lt;SPAN class="" style="color: #008000;"&gt;print&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;GetMessages&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;1&lt;/SPAN&gt;&lt;SPAN class=""&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #008000; font-weight: bold;"&gt;except&lt;/SPAN&gt; &lt;SPAN class=""&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;ExecuteError&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;    &lt;SPAN class="" style="color: #008000;"&gt;print&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;GetMessages&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #666666;"&gt;2&lt;/SPAN&gt;&lt;SPAN class=""&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #008000; font-weight: bold;"&gt;else&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;    &lt;SPAN class="" style="color: #008000;"&gt;print&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #ba2121;"&gt;"Success!"&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #008000; font-weight: bold;"&gt;finally&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;    &lt;SPAN class="" style="color: #008000;"&gt;print&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #ba2121;"&gt;"Complete"&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;I receive back the following error:&lt;/P&gt;&lt;PRE style="color: #000000; background-color: #ffffff; border: 0px; font-size: 14px; padding: 1px 0px;"&gt;&lt;SPAN class="" style="color: #e75c58;"&gt;RuntimeError&lt;/SPAN&gt;: Object: Error in executing tool&lt;/PRE&gt;&lt;P&gt;Any suggestions on what I am doing incorrectly?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcgis online notebooks‌&amp;nbsp;arcgis notebooks beta&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Jun 2020 19:54:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/how-to-add-a-new-field-to-a-hosted-feature-layer/m-p/227352#M36</guid>
      <dc:creator>Chris_Mahlke</dc:creator>
      <dc:date>2020-06-06T19:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a new field to a Hosted Feature Layer?</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/how-to-add-a-new-field-to-a-hosted-feature-layer/m-p/1033685#M252</link>
      <description>&lt;P&gt;I have exactly the same issue, and getting the same error message. My code snippit below. More or less the same as Chris's just organised a bit differently. Hoping someone knows the answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from arcgis.gis import GIS
from arcgis import features
from arcgis.features import FeatureLayer
from arcgis.features import FeatureLayerCollection
arcpy.env.overwriteOutput = True
gis = GIS("https://ausbats.maps.arcgis.com", "&amp;lt;USERNAME&amp;gt;", "&amp;lt;PASSWORD&amp;gt;")
search_result = gis.content.search('title:Hipposideros_ater_X',item_type="Feature Layer")
bat_item = search_result[0]
bat_layers = bat_item.layers
fieldName = 'Taxon'
arcpy.AddField_management(bat_layers,fieldName,"TEXT",field_length=30)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm&amp;nbsp; using Notebooks in ArcGIS Pro&lt;/P&gt;&lt;P&gt;Did you end up finding a solution &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/122021"&gt;@Chris_Mahlke&lt;/a&gt;?&lt;/P&gt;&lt;P&gt;Regards, Damian&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 23:11:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/how-to-add-a-new-field-to-a-hosted-feature-layer/m-p/1033685#M252</guid>
      <dc:creator>Damian</dc:creator>
      <dc:date>2021-03-09T23:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a new field to a Hosted Feature Layer?</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/how-to-add-a-new-field-to-a-hosted-feature-layer/m-p/1034391#M257</link>
      <description>&lt;P&gt;Ok, I finally found a solution. I suspect you can't add a field to an AGOL feature layer using arcpy (I lost count of how many different code variations I tried). I eventually stumbled across &lt;A title="github link" href="https://gist.github.com/mpayson/471516f8a103eba05287402226473bd1" target="_blank" rel="noopener"&gt;this github link&lt;/A&gt; that provided the answer I was after. My code snippit below.&lt;/P&gt;&lt;P&gt;D&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from arcgis.gis import GIS
from arcgis import features
from arcgis.features import FeatureLayer
from arcgis.features import FeatureLayerCollection
arcpy.env.overwriteOutput = True
gis = GIS("https://ausbats.maps.arcgis.com", "&amp;lt;USERNAME&amp;gt;", "&amp;lt;PASSWORD&amp;gt;") 
bat_url = "https://services5.arcgis.com/wkEdAXzuNvKdAtLV/arcgis/rest/services/Hipposideros_ater_X/FeatureServer/0"
bat_fl = FeatureLayer(bat_url,gis)
new_field = {
    "name": "Taxon",
    "type": "esriFieldTypeString",
    "alias": "Taxon",
    "length": 30,
    "nullable": True,
    "editable": True,
    "visible": True,
    "domain": None
}
update_dict = {"fields": [new_field]}
bat_fl.manager.add_to_definition(update_dict)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 11:39:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/how-to-add-a-new-field-to-a-hosted-feature-layer/m-p/1034391#M257</guid>
      <dc:creator>Damian</dc:creator>
      <dc:date>2021-03-09T11:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a new field to a Hosted Feature Layer?</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/how-to-add-a-new-field-to-a-hosted-feature-layer/m-p/1034435#M258</link>
      <description>&lt;P&gt;&lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.managers.html#arcgis.features.managers.FeatureLayerManager.add_to_definition" target="_self"&gt;Using a feature layer manager&lt;/A&gt; via Python, as&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/417320"&gt;@Damian&lt;/a&gt; shows, is certainly one way to do it, and a method that I use often myself. However, there's no limitation on the &lt;STRONG&gt;arcpy.management.AddField() &lt;/STRONG&gt;function that would prevent you from using it against a hosted feature layer. I've tested it, and it works just fine.&lt;/P&gt;&lt;P&gt;This issue, I think, stems from attempting to use the function from a &lt;EM&gt;notebook&lt;/EM&gt;. Using a standard notebook in AGOL, try running &lt;EM&gt;any&lt;/EM&gt; arcpy function and you'll get an error, because arcpy is not an available module in the standard AGOL Notebook environment.&lt;/P&gt;&lt;P&gt;I tried opening your notebook link, but it doesn't show anything. Can you confirm which type of notebook you've got? You can see &lt;A href="https://doc.arcgis.com/en/arcgis-online/reference/use-arcpy-in-your-notebook.htm" target="_self"&gt;in the AGOL docs&lt;/A&gt; that ArcPy &lt;EM&gt;is&lt;/EM&gt; available, but only by using the advanced notebook runtimes. That would be my first guess.&lt;/P&gt;&lt;P&gt;Also, if the notebook still exists, make sure it's public so that others can see the preview page.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 14:19:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/how-to-add-a-new-field-to-a-hosted-feature-layer/m-p/1034435#M258</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-03-09T14:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a new field to a Hosted Feature Layer?</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/how-to-add-a-new-field-to-a-hosted-feature-layer/m-p/1034740#M259</link>
      <description>&lt;P&gt;Hi Josh, thanks for your response.&lt;/P&gt;&lt;P&gt;As mentioned in my previous post, I'm using Notebook in ArcGIS Pro. So ArcPy is definitely available. I assume that your query about the notebook link is directed towards&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/122021"&gt;@Chris_Mahlke&lt;/a&gt; as I didn't post a link. Would you mind posting an example of how you have used&amp;nbsp;arcpy.management.AddField() please&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt; ?&lt;/P&gt;&lt;P&gt;Regards, Damian&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 23:14:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/how-to-add-a-new-field-to-a-hosted-feature-layer/m-p/1034740#M259</guid>
      <dc:creator>Damian</dc:creator>
      <dc:date>2021-03-09T23:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to add a new field to a Hosted Feature Layer?</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/how-to-add-a-new-field-to-a-hosted-feature-layer/m-p/1264827#M627</link>
      <description>&lt;P&gt;Thank you for this.&lt;BR /&gt;&lt;BR /&gt;It helped me solve this excat same problem, but I just used the arcpy.AddField_management method, but using the URL of the Hosted Feature Layer as the 'in_table' parameter. Works a treat.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 04:38:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/how-to-add-a-new-field-to-a-hosted-feature-layer/m-p/1264827#M627</guid>
      <dc:creator>benough</dc:creator>
      <dc:date>2023-03-07T04:38:19Z</dc:date>
    </item>
  </channel>
</rss>

