Good afternoon!
I am trying to write a short script that will periodically be run to check whether there are new rows in hosted layer. When there are new rows, I want a particular field to calculated by combing a string prefix ("NNTREE-") with the OBJECTID value. I found some past discussions on .calulate, several which managed to resolve people's problems, but none dealt specifically with trying to combine a field with a string in this way.
import arcgis
from arcgis.gis import GIS
gis = GIS("pro")
trees = gis.content.get('ebc917bcf648444a8161f4dca4afb7ec')
trees.layers[0].calculate(
where="assetid IS NULL",
calc_expression = {
'field': 'assetid',
"sqlExpression" :'CONCAT("NNTREE-", OBJECTID)'})
Exception:
'Invalid field: NNTREE-' parameter is invalid
(Error Code: 400)
Thank you for any help.
Solved! Go to Solution.
Hey, your calc_expression value should be:
{"field": "assetid", "sqlExpression": "CONCAT('NNTREE-', OBJECTID)"}
Hey, your calc_expression value should be:
{"field": "assetid", "sqlExpression": "CONCAT('NNTREE-', OBJECTID)"}
That' great, thank you. I had managed a slightly more convoluted workaround to achieve the same effect, but this is preferable. I appreciate your help!
Looks like it was just the single/double quotation marks at issue? As someone primarily accustomed to R, I need to get used to there being an important distinction between those two characters in SQL syntax.