# Integration Toolkit - Document Handling

**URL:** <https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [March 20, 2024, 11:28am UTC](https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617 "2024-03-20T11:28:13Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Leech](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alex_leech/32/39391_2.png) [@Alex\_Leech](https://forum.inductiveautomation.com/u/Alex_Leech)\
**Post date:** [March 20, 2024, 11:28am UTC](https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617/1 "2024-03-20T11:28:13Z")

</div>

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:

```auto
{
  "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!

```auto
sum(forEach({this.custom.tagBinding},it()[1])) > 0

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/0/10aaf2a34177ef8af5df64d0a04c380709cf4930.png)

However, if I do a tag binding and then an expression with almost the same code - It fails.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/a/ea0e5d9fb740d27f7a958f856e06aa3f4b80cfb7.png)

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!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 20, 2024, 11:36am UTC](https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617/2 "2024-03-20T11:36:21Z")

</div>

I haven't played much with document tags. I'll have to experiment when I get a moment.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 20, 2024, 11:43am UTC](https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617/3 "2024-03-20T11:43:11Z")

</div>

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](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831) for more.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 20, 2024, 3:48pm UTC](https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617/4 "2024-03-20T15:48:42Z")

</div>

> [@pturmel](#):
>
> I haven't played much with document tags. I'll have to experiment when I get a moment.

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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 20, 2024, 4:22pm UTC](https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617/5 "2024-03-20T16:22:15Z")

</div>

Rather, assigning a document to a Perspective property jsonifies, making it a map.

---

<div class="post-metadata">

**Author:** ![Alex\_Leech](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alex_leech/32/39391_2.png) [@Alex\_Leech](https://forum.inductiveautomation.com/u/Alex_Leech)\
**Post date:** [March 22, 2024, 11:41am UTC](https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617/6 "2024-03-22T11:41:41Z")

</div>

Am I right in saying via expression there isn's an easy 'jsonify' command to do this?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 22, 2024, 11:50am UTC](https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617/7 "2024-03-22T11:50:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Alex\_Leech](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alex_leech/32/39391_2.png) [@Alex\_Leech](https://forum.inductiveautomation.com/u/Alex_Leech)\
**Post date:** [March 26, 2024, 3:22pm UTC](https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617/8 "2024-03-26T15:22:13Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/d/add0649d77c2444aced7e9bec54344791a6e9434.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 26, 2024, 3:37pm UTC](https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617/9 "2024-03-26T15:37:55Z")

</div>

Ok, that shot in the dark was wrong. I'll have to study the document underlying type and write explicit support for it. /:

---

<div class="post-metadata">

**Author:** ![Alex\_Leech](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alex_leech/32/39391_2.png) [@Alex\_Leech](https://forum.inductiveautomation.com/u/Alex_Leech)\
**Post date:** [March 26, 2024, 3:44pm UTC](https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617/10 "2024-03-26T15:44:32Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 26, 2024, 3:49pm UTC](https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617/11 "2024-03-26T15:49:03Z")

</div>

> [@Alex\_Leech](#):
>
> reference tags dont accept

But you should be able to use the `jsonGet()` function for anything else.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 26, 2024, 9:16pm UTC](https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617/12 "2024-03-26T21:16:31Z")

</div>

> [@pturmel](#):
>
> 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.

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 🙂

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 26, 2024, 9:18pm UTC](https://forum.inductiveautomation.com/t/integration-toolkit-document-handling/87617/13 "2024-03-26T21:18:32Z")

</div>

That will save me some time.
