# Installed function return value as attribute value

**URL:** <https://forum.datomic.com/t/installed-function-return-value-as-attribute-value/1981>\
**Category:** Peer API\
**Created:** [October 12, 2021, 1:43am UTC](https://forum.datomic.com/t/installed-function-return-value-as-attribute-value/1981 "2021-10-12T01:43:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![artomis](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@artomis](https://forum.datomic.com/u/artomis)\
**Post date:** [October 12, 2021, 1:43am UTC](https://forum.datomic.com/t/installed-function-return-value-as-attribute-value/1981/1 "2021-10-12T01:43:31Z")

</div>

Hi,

New Datomic user here. I’ve searched but can’t find a definitive answer to this one. We have installed a simple Java function that simply checks that the 3 items passed in are equivalent and returns a boolean. As a test, we would like to have the result of this function stored as a value for an attribute of an entity as we are storing it. This is essentially a case of due diligence/proof-of-concept for us.

Here’s the function source (as simple as it is):  
String source = “return (v1.equals(v2) && v2.equals(v3));”

This is installed and works great with a simple `invoke()` call.

However, what we wanted to try is something like this:

```auto
[[ :db/add "test-id" :test/bool [ :test/func 1 1 1] ] ]
// or:
[[ :db/add "test-id" :test/bool ( :test/func 1 1 1 )] ]
// or even:
[{ :db/id "test-id" :test/bool [ :test/func 1 1 1] } ]

```

(we have tried several different syntaxes all with the same (or similar) result:

```auto
:db.error/wrong-type-for-attribute Value [:test/func, 1, 1, 1] is not a valid :bool for attribute :test/bool

```

I’m assuming we are doing something very wrong … or this is not something that is possible. Are we tilting at windmills?

TIA.

---

<div class="post-metadata">

**Author:** ![nikolayandr](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/nikolayandr/32/375_2.png) [@nikolayandr](https://forum.datomic.com/u/nikolayandr)\
**Post date:** [October 12, 2021, 9:51am UTC](https://forum.datomic.com/t/installed-function-return-value-as-attribute-value/1981/2 "2021-10-12T09:51:22Z")

</div>

You can’t call a function inside another transaction statement but you can call your function as a separate statement. The result of function is treated then as a statement to be executed in the same trasansaction.

```auto
(d/transact conn {
             :tx-data [
[:test/func 1 1 1]
]})

```

whereas your function ` :test/func` should return a list: ` [:db/add "test-id" :test/bool <result of comparing>]`

So it looks as replacing of `[:test/func 1 1 1]` by the result returned from `:test/func`

---

<div class="post-metadata">

**Author:** ![artomis](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@artomis](https://forum.datomic.com/u/artomis)\
**Post date:** [October 12, 2021, 5:35pm UTC](https://forum.datomic.com/t/installed-function-return-value-as-attribute-value/1981/3 "2021-10-12T17:35:39Z")

</div>

Thanks @nikolayandr . This confirms my suspicion that _any_ function we install that is to used in a transaction is required to be a **transaction function** as defined in the Datomic docs. It wasn’t clear to me whether this was an obligation or not. This clarifies things for us.

Thx again.

(Off to find more windmills. 🙂 )
