<?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 can I Calculate a field in a hosted feature class using Rest API? in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/how-can-i-calculate-a-field-in-a-hosted-feature/m-p/636590#M31714</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you ever get this figured out? I have the same question.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Jan 2020 18:55:23 GMT</pubDate>
    <dc:creator>joerodmey</dc:creator>
    <dc:date>2020-01-16T18:55:23Z</dc:date>
    <item>
      <title>How can I Calculate a field in a hosted feature class using Rest API?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-can-i-calculate-a-field-in-a-hosted-feature/m-p/636589#M31713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a Damage Assessment feature layer hosted on AGOL with a web map.&amp;nbsp; 50k points.&amp;nbsp; Along with Domain controlled fields are Estimated % of Damage, Estimated $ Amt of Damage and a prepopulated Dwelling Value field.&amp;nbsp; Field type is Double on these 3 fields.&amp;nbsp; I need to either&lt;/P&gt;&lt;P&gt;1.&amp;nbsp; Calc (Est $ Damage = DwellingVal * Est % Damage) on the fly as the user enters data for each point.&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; Create a URL to Calc (Est $ Damage = DwellingVal * Est % Damage) where (Est % Damage is &amp;gt;0).&amp;nbsp; AGOL times out&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; calc-ing the 50k records so I think the Where clause is necessary to only capture the 500 or 5000 that are damaged.&lt;/P&gt;&lt;P&gt;3.&amp;nbsp; I'm open to ANY suggestion!&amp;nbsp; Thanks. Allan&lt;/P&gt;&lt;P&gt;I can't get the REST API grid to work. The error says that the calcexpression is invalid:&lt;/P&gt;&lt;P&gt;Where: PercentDamage &amp;gt; 0&lt;/P&gt;&lt;P&gt;"calcExpression":[{"field" : "EstDollarDamage", "sqlExpression" : "DwellingVal*PercentDamage*.01"}]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://services5.arcgis.com/cA4ofagPaJJ7qhEz/arcgis/rest/services/DamageAssessment_O_only/FeatureServer/0/calculate(where=”PercentDamage"&gt;http://services5.arcgis.com/cA4ofagPaJJ7qhEz/arcgis/rest/services/DamageAssessment_O_only/FeatureServer/0/calculate(where=”PercentDamage&lt;/A&gt; &amp;gt; 10 2”,calcExpression={“field”: “EstDollarDamage”,“sqlexpression” : "DwellingVal*PercentDamage*.01"})&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Jun 2016 15:54:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-can-i-calculate-a-field-in-a-hosted-feature/m-p/636589#M31713</guid>
      <dc:creator>AllanLambert</dc:creator>
      <dc:date>2016-06-27T15:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: How can I Calculate a field in a hosted feature class using Rest API?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-can-i-calculate-a-field-in-a-hosted-feature/m-p/636590#M31714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you ever get this figured out? I have the same question.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jan 2020 18:55:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-can-i-calculate-a-field-in-a-hosted-feature/m-p/636590#M31714</guid>
      <dc:creator>joerodmey</dc:creator>
      <dc:date>2020-01-16T18:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: How can I Calculate a field in a hosted feature class using Rest API?</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-can-i-calculate-a-field-in-a-hosted-feature/m-p/636591#M31715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I called Tech Support a couple months later and luckily talked to the most helpful guy who wrote this py script in a couple hours.&amp;nbsp; I don't think ESRI "gives" this kind of help anymore.&amp;nbsp; I can't put my hands on the token documentation.&amp;nbsp; I put this script in a sched task and it runs every 5 mins during storm damage assessment.&amp;nbsp; Good Luck. Allan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV&gt;import urllib&lt;BR /&gt;import urllib2&lt;BR /&gt;import httplib&lt;BR /&gt;import json&lt;/DIV&gt;&lt;DIV&gt;##Token Generation Parameters&lt;BR /&gt;tokenUrl = 'https://www.arcgis.com/sharing/oauth2/token'&lt;BR /&gt;featureServiceURL = 'https://services5.arcgis.com/xxxxxxxxx/arcgis/rest/services/MyDamageAssessmentService2019/FeatureServer/0/calculate'&lt;BR /&gt;clientId = 'xxxxxxxxxxxx'&lt;BR /&gt;clientSecret = 'xxxxxxxxxxxxxxxxxxx'&lt;/DIV&gt;&lt;DIV&gt;##Calculate Parameters - Only calc if a property has been assessed PercentDam &amp;gt; 0&lt;BR /&gt;whereClause = 'PercentDam &amp;gt; 0'&lt;BR /&gt;updateExpression = [{"field":"EstDollarD","sqlExpression":"Dwlgval1*PercentDam*.01"}]&lt;/DIV&gt;&lt;DIV&gt;def sendRequest(url, parameters):&lt;BR /&gt;&amp;nbsp;data = urllib.urlencode(parameters)&lt;BR /&gt;&amp;nbsp;req = urllib2.Request(url, data)&lt;BR /&gt;&amp;nbsp;response = urllib2.urlopen(req)&lt;BR /&gt;&amp;nbsp;return json.loads(response.read())&lt;/DIV&gt;&lt;DIV&gt;def generateToken():&lt;BR /&gt;&amp;nbsp;tokenParameters = {'client_id': clientId, 'client_secret': clientSecret, 'grant_type':'client_credentials'}&lt;BR /&gt;&amp;nbsp;jsonResponse = sendRequest(tokenUrl, tokenParameters)&lt;BR /&gt;&amp;nbsp;token = jsonResponse["access_token"]&lt;BR /&gt;&amp;nbsp;return token&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;def calculateValues(token):&lt;BR /&gt;&amp;nbsp;calculateParameters = {'where':whereClause,'calcExpression':updateExpression,'sqlFormat':'standard','rollbackOnArithmaticError':'false','token':token, 'f':'json'}&lt;BR /&gt;&amp;nbsp;jsonResponse = sendRequest(featureServiceURL, calculateParameters)&lt;BR /&gt;&amp;nbsp;if jsonResponse['success'] == True:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;print "Updated Feature Count: " + str(jsonResponse["updatedFeatureCount"])&lt;BR /&gt;&amp;nbsp;else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;print "Calculate operation failed"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;print jsonResponse&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;token = generateToken()&lt;BR /&gt;calculateValues(token)&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jan 2020 19:42:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-can-i-calculate-a-field-in-a-hosted-feature/m-p/636591#M31715</guid>
      <dc:creator>AllanLambert</dc:creator>
      <dc:date>2020-01-16T19:42:51Z</dc:date>
    </item>
  </channel>
</rss>

