Creating custom pop-up attribute expressions using ArcGIS API for Python

05-26-2020 02:59 PM
New Contributor

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
#Check to see if web map updated

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?

1 Reply
New Contributor III

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   
wm_object.layers[0].popupInfo.fieldInfos = field_info

# #Update web map
0 Kudos