Select to view content in your preferred language

FeatuerLayer .caculate that concatenates a field with a standalone string

454
2
Jump to solution
12-01-2023 01:36 PM
CameronAndrew
Emerging Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
EarlMedina
Esri Regular Contributor

Hey, your calc_expression value should be:

{"field": "assetid", "sqlExpression": "CONCAT('NNTREE-', OBJECTID)"}

 

View solution in original post

0 Kudos
2 Replies
EarlMedina
Esri Regular Contributor

Hey, your calc_expression value should be:

{"field": "assetid", "sqlExpression": "CONCAT('NNTREE-', OBJECTID)"}

 

0 Kudos
CameronAndrew
Emerging Contributor

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.

0 Kudos