I'm trying to use python to create a custom pop-up attribute expression in an ArcGIS Online Web Map, but I'm running into some issues.
Here is the python code I am running in an ArcGIS Pro Notebook:
import arcgis
#Connect to ArcGIS Online using active portal in ArcGIS Pro
gis = arcgis.gis.GIS("pro")
#Get web map, and create a custom attribute expression
wm_item = gis.content.get("84a22dc69c57437d97292a12f05cf4d7")
wm_object = arcgis.mapping.WebMap(wm_item)
wm_object.layers[0].popupInfo.expressionInfos = [{
"name": "expr1",
"title": "test",
"expression": "'test'",
"returnType": "text"
}]
#Update web map
wm_object.update()
#Check to see if web map updated
wm_object.layers[0].popupInfo.expressionInfos
The code appears to be working correctly, as I can see the expression I created when I open the web map's "configure pop-up" settings in a web browser:
However, when I click on a feature in the web map, the custom attribute I created is no where to be found:
Anyone know how to fix this?
I have the same issue. Likely related to bug 000139253
Workaround is to append your expressions to fieldInfos
field1 = {
"fieldName": "expression/expr1",
"visible": "true"
}
field2 = {
"fieldName": "expression/expr2",
"visible": "true"
}
field_info = wm_object.layers[0].popupInfo.fieldInfos
field_info.extend([field1,field2])
wm_object.layers[0].popupInfo.fieldInfos = field_info
# #Update web map
wm_object.update()