Summary:
Detailed Steps:
I've created a AGOL view called test_layer_view on a hosted feature layer:
In the view, using the Admin REST API, I want to add a expression field as a test, calculating 1+1.
I'm not using the view's top-level feature layer...
...Instead, I'm using the sublayer:
(Let me know if I'm using the wrong item. Although I tested with the top-level feature layer view, and had the same issue with it.)
I got some sample JSON from the ArcGIS REST APIs > Add to Definition (Feature Service) documentation:
(Those docs are pretty complicated and geared towards joins, so I'm not sure how to boil the sample JSON down to just a simple expression field without a join.)
{
"sourceLayerFields": [
{
"name": "test_expression_field",
"alias": "test_expression_field",
"expression": "1+1",
"type": "esriFieldTypeInteger"
}
]
}
I hit the "Add To Layer Definition" button and it ran without errors:
But when I refresh the view's Data > Fields tab (or the Table tab), the expression field is missing.
Likewise, the expression field is missing from the sublayer's JSON definition.
What am I doing wrong?
Hey Bud, expressions are limited to joined views. I don't think it will work with regular view layers.
@KhaledHassen can confirm?
Idea: Expression field in advanced AGOL view without join
It's still unclear if this is supported or not. If it's not supported, it would help if the docs could explain this.
Edit:
Esri Case #04171628 - ArcGIS Online Admin REST API - Are expression fields in advanced views without joins supported?
That workflow is not supported, unfortunately. Expressions can only exist on the parent layer for advanced views which have relatedTable objects within the JSON payload. That approach works for standard fields (not expression fields) but advanced views are read-only and so you could not manually calculate the field after it has been added.