Hi everyone,
I am trying to create an advanced view according to this documentation Advanced views , this is my code:
{
"layers": [
{
"name": "VistaAvanzada",
"description": "AttributeJoin",
"adminLayerInfo": {
"viewLayerDefinition": {
"table": {
"name": "target",
"sourceServiceName": "TestJoinExpression_Tabla1",
"sourceLayerId": 0,
"sourceLayerFields": [
{
"name": "key1",
"alias": "key1",
"source": "key1"
},
{
"name": "date1",
"alias": "date1",
"source": "date1"
}
],
"relatedTables": [
{
"name": "joined",
"sourceServiceName": "TestJoinExpression_Tabla2",
"sourceLayerId": 0,
"sourceLayerFields": [
{
"name": "key1related",
"alias": "key1related",
"source": "key1related"
},
{
"name": "name",
"alias": "name",
"source": "name"
},
{
"name": "relatedExpression",
"alias": "SumNumsTest",
"expression": "Num1 + Num2",
"type": "esriFieldTypeInteger"
}
],
"type": "INNER",
"parentKeyFields": [
"key1",
"key2"
],
"keyFields": [
"key1related",
"key2related"
]
}
]
}
}
}
}
]
}
For this test, I have created the fields Num1 and Num2, in both tables, because I am not sure how the expression works, however the expression field "relatedExpression" is not created, I can see the fields I declared, coming from both tables. That is, the view works for me as a union of tables, but I cannot create the additional field that corresponds to the expression.
I appreciate the help
It has been 2 years so I am not sure if you already have it fixed yet, but I got it solved by adding "source" property to field object referring to at least one field whose value being used in the expression, then the field displayed normally.
Example:
[
{ // calculate value on single field
"name": "testField",
"type": "esriFieldTypeInteger",
"alias": "testField",
"expression": "myNumberField1 * 2",
"source": "myNumberField1"
},
{ // calculate value on multiple fields, only one field needed in source
"name": "testField2",
"type": "esriFieldTypeInteger",
"alias": "testField2",
"expression": "myNumberField1 + myNumberField2",
"source": "myNumberField1"
},
{ // calculate static value for all records, source field must be there even it is irrelevant
"name": "testField3",
"type": "esriFieldTypeString",
"alias": "testField3",
"expression": "'Hello World!'",
"source": "OBJECTID"
},
{ // example of advanced SQL to get hour part from date field
"name": "hourOfDay",
"type": "esriFieldTypeInteger",
"alias": "hourOfDay",
"expression": "DATEPART(HOUR, myDateField)",
"source": "myDateField"
}
]
Hope this helps.