<?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: Update Field Values in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/update-field-values/m-p/1398636#M70096</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/633156"&gt;@kapalczynski&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;An easier approach may be to use arcpy.&amp;nbsp; Ex:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Variables
portalURL = 'https://gis.esri.com/portal'
username = 'portaladmin'
password = 'p0rt@l@dmin1'
featureServiceURL = 'https://gis.esri.com/server/rest/services/pipes/FeatureServer/0'

# Sign into Portal
arcpy.SignInToPortal(portalURL, username, password)

# Calculate Field
arcpy.management.CalculateField(
    in_table=featureServiceURL,
    field="FLAGFIELD",
    expression="'YES'",
    expression_type="PYTHON3",
    code_block="",
    field_type="TEXT",
    enforce_domains="NO_ENFORCE_DOMAINS"
)&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 20 Mar 2024 18:20:27 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2024-03-20T18:20:27Z</dc:date>
    <item>
      <title>Update Field Values</title>
      <link>https://community.esri.com/t5/python-questions/update-field-values/m-p/1398471#M70095</link>
      <description>&lt;P&gt;I have a question...I am trying to update a specific field with the code below. I want to query all the data and change a field named "FLAGFIELD" to YES&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can get at the Portal ID for the Service and point to the correct table and set the proper JSON payload...&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I am missing where I am querying or selecting with a where clause of 1=1&lt;/P&gt;&lt;P&gt;Can anyone help with this part?&amp;nbsp; How do I "Change ALL records to YES in the field FLAGFIELD"&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    gis = GIS("https://xxxxxxx", "xxxxxx", "xxxxxxxx")
    #currenttoken = gis._con.token
    portal_item = gis.content.get('b373b127exxxxxxxxxx0dfb14a1')
    ports_layer = portal_item.tables[0]

    # We need to reconstruct json features to be updated
    FLAGFIELDvalue = 'YES'

    # construct json
    add_data = {
          "attributes" : {
            "FLAGFIELD" : FLAGFIELDvalue, 
          }
        }
    # Push updates
    add_updates = ports_layer.edit_features(updates = [add_data])&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 20 Mar 2024 15:36:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-field-values/m-p/1398471#M70095</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-03-20T15:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: Update Field Values</title>
      <link>https://community.esri.com/t5/python-questions/update-field-values/m-p/1398636#M70096</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/633156"&gt;@kapalczynski&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;An easier approach may be to use arcpy.&amp;nbsp; Ex:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Variables
portalURL = 'https://gis.esri.com/portal'
username = 'portaladmin'
password = 'p0rt@l@dmin1'
featureServiceURL = 'https://gis.esri.com/server/rest/services/pipes/FeatureServer/0'

# Sign into Portal
arcpy.SignInToPortal(portalURL, username, password)

# Calculate Field
arcpy.management.CalculateField(
    in_table=featureServiceURL,
    field="FLAGFIELD",
    expression="'YES'",
    expression_type="PYTHON3",
    code_block="",
    field_type="TEXT",
    enforce_domains="NO_ENFORCE_DOMAINS"
)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 20 Mar 2024 18:20:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-field-values/m-p/1398636#M70096</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-03-20T18:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: Update Field Values</title>
      <link>https://community.esri.com/t5/python-questions/update-field-values/m-p/1398650#M70097</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10527"&gt;@JakeSkinner&lt;/a&gt;&amp;nbsp; thanks... that is way easier... not sure when to use one or the other... still a bit confused there&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 18:44:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-field-values/m-p/1398650#M70097</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-03-20T18:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: Update Field Values</title>
      <link>https://community.esri.com/t5/python-questions/update-field-values/m-p/1398653#M70099</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10527"&gt;@JakeSkinner&lt;/a&gt;&amp;nbsp;&amp;nbsp; How could I add a WHERE clause to that ... so update the field value only when XXX&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 18:54:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-field-values/m-p/1398653#M70099</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-03-20T18:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: Update Field Values</title>
      <link>https://community.esri.com/t5/python-questions/update-field-values/m-p/1398659#M70101</link>
      <description>&lt;P&gt;I tend to stick to arcpy when the functionality is available in both arcpy and ArcGIS API for Python.&amp;nbsp; It minimizes the code you will have to write.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the WHERE clause, you can first create a Feature Layer using the Make Feature Layer tool.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 18:57:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-field-values/m-p/1398659#M70101</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-03-20T18:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Update Field Values</title>
      <link>https://community.esri.com/t5/python-questions/update-field-values/m-p/1399191#M70118</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10527"&gt;@JakeSkinner&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So create a layer from the inputFeatureLayer where the field "Imported = No" and dump the results into an InMemory Layer&lt;/P&gt;&lt;P&gt;From there I need to query the InMemory layer (r"memory\importedRecords") and append that to the main Feature...&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    inputFeatureLayer = r'https://gggg.gov/hosting/rest/services/Hosted/Public_DEV_View/FeatureServer/0'
    outputFeatureLayer = r'https://gggg.gov/hosting/rest/services/Hosted/Public_/FeatureServer/0'
    whereClause = "Imported = 'No'"
    arcpy.MakeFeatureLayer_management(inputFeatureLayer, r"memory\importedRecords", whereClause )
    arcpy.management.Append(r"memory\importedRecords"], outputFeatureLayer, "TEST_AND_SKIP")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 18:43:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-field-values/m-p/1399191#M70118</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-03-21T18:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: Update Field Values</title>
      <link>https://community.esri.com/t5/python-questions/update-field-values/m-p/1399195#M70119</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/633156"&gt;@kapalczynski&lt;/a&gt;&amp;nbsp;you can run the Calculate Field on the feature layer and the edits will be reflected in the service:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Variables
portalURL = 'https://gis.esri.com/portal'
username = 'portaladmin'
password = 'p0rt@l@dmin1'
featureServiceURL = 'https://gis.esri.com/server/rest/services/pipes/FeatureServer/0'
whereClause = "Imported = 'No'"

# Sign into Portal
arcpy.SignInToPortal(portalURL, username, password)

# Make Feature Layer
arcpy.MakeFeatureLayer_management(featureServiceURL, "fLyr", whereClause)

# Calculate Field
arcpy.management.CalculateField(
    in_table="fLyr",
    field="FLAGFIELD",
    expression="'YES'",
    expression_type="PYTHON3",
    code_block="",
    field_type="TEXT",
    enforce_domains="NO_ENFORCE_DOMAINS"
)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 21 Mar 2024 18:42:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-field-values/m-p/1399195#M70119</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-03-21T18:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Update Field Values</title>
      <link>https://community.esri.com/t5/python-questions/update-field-values/m-p/1399296#M70124</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10527"&gt;@JakeSkinner&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does it matter if the Layer is Hosted?&amp;nbsp; I am try that and getting errors..&lt;/P&gt;&lt;P&gt;The Hosted FS is Public and not token needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    portalURL = 'https://xxxx.gov/portal'
    username = 'xxxx'
    password = 'xxxx'
    arcpy.SignInToPortal(portalURL, username, password)

    inputFeatureLayer = r"https://dfdfdf.gov/hosting/rest/services/Hosted/DEV_H/FeatureServer/3"
    whereClause = "Imported = 'Yes'"
    #arcpy.MakeFeatureLayer_management(inputFeatureLayer, r"memory\importedRecords", whereClause )
    arcpy.MakeFeatureLayer_management(inputFeatureLayer, "fLyr", whereClause )
    arcpy.management.CalculateField(
        in_table= "fLyr",
        field="Imported",
        expression="'No'",
        expression_type="PYTHON3",
        code_block="",
        field_type="TEXT",
        enforce_domains="NO_ENFORCE_DOMAINS"
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in &amp;lt;lambda&amp;gt;&lt;BR /&gt;return lambda *args: val(*gp_fixargs(args, True))&lt;BR /&gt;arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000732: Input Features: Dataset &lt;A href="https://xxxx.gov/hosting/rest/services/Hosted/DEV_H/FeatureServer/3" target="_blank" rel="noopener"&gt;https://xxxx.gov/hosting/rest/services/Hosted/DEV_H/FeatureServer/3&lt;/A&gt; does not exist or is not supported&lt;BR /&gt;Failed to execute (MakeFeatureLayer).&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 20:52:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-field-values/m-p/1399296#M70124</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-03-21T20:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Update Field Values</title>
      <link>https://community.esri.com/t5/python-questions/update-field-values/m-p/1399321#M70125</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10527"&gt;@JakeSkinner&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT&lt;/P&gt;&lt;P&gt;I forgot to mention that this was a table that I was trying to update... not a feature class ... Is there a make table?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 22:19:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-field-values/m-p/1399321#M70125</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-03-21T22:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Update Field Values</title>
      <link>https://community.esri.com/t5/python-questions/update-field-values/m-p/1399344#M70126</link>
      <description>&lt;P&gt;Think I got it with this&lt;/P&gt;&lt;LI-CODE lang="c"&gt;arcpy.management.MakeTableView(inputFeatureTable, "fLyr", whereClause )

arcpy.management.CalculateField(
in_table= "fLyr",
field="IMPORTED",
expression="'Yes'",
expression_type="PYTHON3",
code_block="",
field_type="TEXT",
enforce_domains="NO_ENFORCE_DOMAINS"
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 22:23:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-field-values/m-p/1399344#M70126</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-03-21T22:23:39Z</dc:date>
    </item>
  </channel>
</rss>

