Hi all,
I'm trying to use the Integration Toolkit to use expressions over scripts, and have hit a brick wall with the document datatype.
Lets say I have a document tag with value as below:
{
"InvalidBays": false,
"InvalidFillID": false,
"InvalidSQL": false,
"InvalidStep": false,
"InvalidPSV": false,
"InvalidPars": false
}
I would like to make an overall 'Error' flag.
If I first bind the tag to a property, and then run the following expression, all works fine!
sum(forEach({this.custom.tagBinding},it()[1])) > 0
However, if I do a tag binding and then an expression with almost the same code - It fails.
I guess this means theres some form of backend data conversion going on when its bound to a property (Like jsonDecode type thing). Is there any way I can replicate this in an expression? or do I just use scripts at this point?
I was originally trying to make an expression tag in a UDT for this hence not just using the binding.
Thanks!
Alex
Edit: Change markdown to preformatted text - Thanks Transistor!
I haven't played much with document tags. I'll have to experiment when I get a moment.
1 Like
Tips: The forum markdown syntax uses >
for quotations. For code it uses backticks to preserve indentation and line breaks. See Wiki - how to post code on this forum for more.
1 Like
I'm betting that we're delivering a Document or JsonObject in a direct expression tag read, and an actual Java map in the transform.
Rather, assigning a document to a Perspective property jsonifies, making it a map.
Am I right in saying via expression there isn's an easy 'jsonify' command to do this?
No, because it isn't really jsonification, but conversion to Perspective's internal array and object types that are its correlates to JSON. Documents from tags can be accessed from expressions using the expression language's bracket operator, so the map and list interfaces must be partly exposed. But obvious not iteration.
Try wrapping the document tag reference in my asMap()
function, then iterating.
Thanks for the explanation!
We've no issues with accessing one layer of document tags with square brackets, but if you have 'anything more'. i.e. An array or dict within the doc, they dont seem to work anymore! Ignore this long day! Just doesnt work in a reference tag.
asMap gives a strange error as it seems to think theres only one arg? (Which kinda check out as a dataset conversion also goes to 1Rx1C). Its like it doesnt think its actually a dict
Ok, that shot in the dark was wrong. I'll have to study the document underlying type and write explicit support for it. /:
Sorry!
On the brightside I have a workaround for this project
During this adventure I've also discovered that reference tags dont accept the square bracket notation for access any further than 1 layer - The more you know!
But you should be able to use the jsonGet()
function for anything else.
Internally, SubscriptExpression
is just a series of if/elif branches, in this specific order:
- List
- (IA) Gson JsonArray, IA "DocumentArray"
- Map
- (IA) Gson JsonObject, IA "Document"
- PropertySet
- Java Array
- Dataset
Obviously as far as I know that represents all the possible cases you'll get as an expression
That will save me some time.