Skip to main content

I am receiving this error below when I try to retrieve the getJSON variable:

Python Exception <Exception>: Unable to update feature service layer definition.
Object reference not set to an instance of an object.
(Error Code: 400)
Error encountered while calling function `processFeature'
PythonCaller_3 (PythonFactory): PythonFactory failed to process feature
PythonCaller_3 (PythonFactory): A fatal error has occurred. Check the logfile above for details
A fatal error has occurred. Check the logfile above for details
JSONFormatter (JSONFormatterFactory):

This is the code in PythonCaller (simplified for readability):

import fme
import fmeobjects
from arcgis.gis import GIS
 
def processFeature(feature):
   getJSON = feature.getAttribute('JSON')
   gis = GIS(profile='username') 
   lyr = gis.content.get('item_id').layers
   for lyr in gis.content.get('item_id').layers:
      lyr.manager.update_definition(getJSON)

I know getJSON is giving me issues because if I replace lyr.manager.update_definition(getJSON) with lyr.manager.update_definition({ "fields" :  { "name" : "FIELDNAME", "domain" : { "type" : "codedValue", "name" : "DOMAINNAME" : n { "name" : "TEST", "code" : "TEST" }, { "name" : "TEST1", "code" : "TEST1" }, { "name" : "TEST2", "code" : "TEST2" } ] } } ] } then it works. 

 

Essentially, I like to create a JSON object in an attribute using JSONTemplater and put it into PythonCaller so I don't have to hardcode the JSON object. 

 

Thanks in advance!

Alternatively, I was able to edit coded value domains using HTTPCaller. This now allows me to update new coded value domains to an existing feature class from data collected in Survey123.

 

Below are some of the tips that got me through this issue:

 

Screenshot of my HTTPCaller parameters for reference:

httpcaller


getAttribute() returns a string, where as update_definition() seems to expect a dict.

Possible workaround:

import fmeobjects
from arcgis.gis import GIS
import json
 
def processFeature(feature):
   # parse str to dict
   getJSON = json.loads(feature.getAttribute('JSON'))
   gis = GIS(profile='username') 
   lyr = gis.content.get('item_id').layers
   for lyr in gis.content.get('item_id').layers:
      lyr.manager.update_definition(getJSON)

 


getAttribute() returns a string, where as update_definition() seems to expect a dict.

Possible workaround:

import fmeobjects
from arcgis.gis import GIS
import json
 
def processFeature(feature):
   # parse str to dict
   getJSON = json.loads(feature.getAttribute('JSON'))
   gis = GIS(profile='username') 
   lyr = gis.content.get('item_id').layers
   for lyr in gis.content.get('item_id').layers:
      lyr.manager.update_definition(getJSON)

 

Thanks for the quick reply! Parsing JSON str to dictionary resolved the issue. The API reference documented this but now I understand how to parse it. Good to know, thank you! 👍 


Alternatively, I was able to edit coded value domains using HTTPCaller. This now allows me to update new coded value domains to an existing feature class from data collected in Survey123.

 

Below are some of the tips that got me through this issue:

 

Screenshot of my HTTPCaller parameters for reference:

httpcaller

I compared using PythonCaller and HTTPCaller and realized HTTPCaller finishes ~3x faster.


getAttribute() returns a string, where as update_definition() seems to expect a dict.

Possible workaround:

import fmeobjects
from arcgis.gis import GIS
import json
 
def processFeature(feature):
   # parse str to dict
   getJSON = json.loads(feature.getAttribute('JSON'))
   gis = GIS(profile='username') 
   lyr = gis.content.get('item_id').layers
   for lyr in gis.content.get('item_id').layers:
      lyr.manager.update_definition(getJSON)

 

This worked like a charm, but somehow I get an error when trying to import json. 

Python Exception <ModuleNotFoundError>: No module named 'ujson'

Does anyone have a clue what is happening here? 


This worked like a charm, but somehow I get an error when trying to import json.

Python Exception <ModuleNotFoundError>: No module named 'ujson'

Does anyone have a clue what is happening here?

Sounds like a problem with a third-party module.

Have you tried setting different Python interpreters in your workspace?


This worked like a charm, but somehow I get an error when trying to import json.

Python Exception <ModuleNotFoundError>: No module named 'ujson'

Does anyone have a clue what is happening here?

Thanks David, it looks like that indeed; Have to look into the extra module; case closed for now.


Alternatively, I was able to edit coded value domains using HTTPCaller. This now allows me to update new coded value domains to an existing feature class from data collected in Survey123.

 

Below are some of the tips that got me through this issue:

 

Screenshot of my HTTPCaller parameters for reference:

httpcaller

Hello! I'm trying to accomplish the same task in Survey 123 but I'm getting hung up pulling down the initial domain values. Do you have an example workspace you may be able to share?


Hello! I'm trying to accomplish the same task in Survey 123 but I'm getting hung up pulling down the initial domain values. Do you have an example workspace you may be able to share?

Hi @vhruska​ I would post a new question on the community and refer to this thread as this question is quite old. Hope this helps.


Reply