Custom Module Return array of objects

Hi All,

I am trying to build a java module for ignition and have run into an issue. I would like to send back data to populate a drop down which is an array of objects [{‘value’:‘example’,‘label’:example},{…},…]. Right now I have it working but inside a script I am forced to write:

import ast
self.props.options = []
for category in system.meslite.pdefm.materialcategory.getMaterialCategoriesParentDropdown():
	self.props.options.append(ast.literal_eval(str(vars(category))))

My question what is the data type I need to return in my java code to simply write in the script.
self.props.options = system.meslite.pdefm.materialcategory.getMaterialCategoriesParentDropdown()

Java Code

@Override
  protected Dict[] getMaterialCategoriesParentDropdownImpl() throws ApiException {
    List<MaterialCategoryDto> materialCategoryDtos = api.getAllMaterialCategories();
    int listSize = materialCategoryDtos.size();
    Dict[] materialCategories = new Dict[listSize];
    for (int i = 0; i<listSize; i++){
      Dict category = new Dict();
      category.__setattr__(Py.newString("value"),
          Py.newString(Objects.requireNonNull(materialCategoryDtos.get(i).getUid()).toString()));
      category.__setattr__(Py.newString("label"),Py.newString(
          Objects.requireNonNull(materialCategoryDtos.get(i).getCategoryName())));
      materialCategories[i] = category;
    }
    return materialCategories;
  }

Try returning a PyStringMap, or a PyList of PyStringMaps.

This got me closer however when I set the result of my method to the drop down it is returned as strings instead of objects.

Script to load data

self.props.options = system.meslite.pdefm.materialcategory.getMaterialCategoriesParentDropdown()

Whoops. What about a PyDictionary, specifically, rather than a PyStringMap? I see a bug.

That does the job!

Thank you very much,
Jordan

1 Like