Binding Property to Document Memory Tag

I would like to store data in a document tag and allow users to view & modify the data using a perspective table. The table is bound to a custom property:
Custom Property

So far, I can get the table to display the data, but I can’t figure out how to write changes back to the tag. If I set the binding to “Bi-Directional”, values immediately revert if I try to change them.

I have also tried disabling the “Bi-Directional” option and creating a “Save” button to write back with a script. This seems the most promising, but I’m still having trouble.

This code works if I create a dictionary and write it to the document tag.

value = system.util.jsonEncode(str(dict))

But if I try to encode the bound property like this:

parValue = self.view.custom.object
value = system.util.jsonEncode(str(parValue))

My memory tag gets a bad value:

Anyone have any ideas?

We’ve not had luck with bidirectional bindings on objects primarily because the elements within objects do not trigger an update. If you want to go with a bidirectional binding, you might have better luck rewriting the modified object back to the property e.g.

copiedObject = dict(self.view.custom.object)
copiedObject[“key”] = value

self.view.custom.object = system.util.jsonEncode(copiedObject)

Disclaimer: I have not tested this.

That said, I think the Save button is the better route. In that case, you should be able to type cast the JavaScript object into a dictionary before encoding to JSON.

parValue = self.view.custom.object
value = system.util.jsonEncode(dict(parValue))

Hope this helps!

1 Like

Thanks @KGarner. I had a chance to work on this again tonight, but I’m still having issues.

When I try to use system.util.jsonEncode(dict(parValue))

I get an error:
RuntimeError: maximum recursion depth exceeded (Java StackOverflowError)

I’m not sure if this is related to the data in my tag or a problem with my code.

I was able to get some other code to work where I load the document tag, modify the value, and write it back. But I can’t figure out how to do the same thing using data from a view parameter.

Just talked to support about the error in my last comment. I’ll try to explain this, but anyone with more knowledge is welcome to jump in if I slaughter this explanation.

Using system.util.jsonEncode with simple view parameters work fine, but if the parameter contains an array, it doesn’t work. This is because view parameters are not primitive types like ‘list’ or ‘dictionary’, but instead use a wrapper type and need to be converted to work with some functions.

Here is the code required to write a view parameter named ‘object’ to a document memory tag:

from com.inductiveautomation.ignition.common import TypeUtilities
parValue = unicode(TypeUtilities.pyToGson(self.view.custom.object))
system.tag.write(path, parValue)

Thanks to Mitchell at Inductive support for helping me find the solution.