# Reusing function implemented in Trigger context in a Script

**URL:** <https://forum.canton.network/t/reusing-function-implemented-in-trigger-context-in-a-script/6036>\
**Category:** App Development\
**Tags:** daml, trigger, script\
**Created:** [January 27, 2023, 3:05pm UTC](https://forum.canton.network/t/reusing-function-implemented-in-trigger-context-in-a-script/6036 "2023-01-27T15:05:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joao\_Santos\_92](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/joao_santos_92/32/5780_2.png) [@Joao\_Santos\_92](https://forum.canton.network/u/Joao_Santos_92)\
**Post date:** [January 27, 2023, 3:05pm UTC](https://forum.canton.network/t/reusing-function-implemented-in-trigger-context-in-a-script/6036/1 "2023-01-27T15:05:21Z")

</div>

Hello community,

I’ve got this scenario where I would like to perform some tests and for that purpose reuse a function  
implemented in a trigger.  
I’ve got these two templates defined elsewhere similar to I show below:  
`template T1`  
`	with`  
` a: Party`  
` b: Text`  
` c: Int`  
` .. (other fields)`  
`	choice Processing_Choice `  
` with `  
` d : ContractId T2`  
` controller a` `template T2`  
`	with`  
` a: Party`  
` b: Text`  
` c: Int`  
`	key (a,b,c) : (Party, Text, Int)`

Then there is a trigger that is on the lookout for these templates as well as is processing them, a trigger with a code similar to what is described below:  
`trigger `  
` t1s <- query T1`  
` calls nontrivial_match_func t1s >>= case`  
`	Some (t1Cid, t2Cid) -> exercises t1Cid Processing_Choice`

`nontrivial_match_func t1s`  
` find and return the first pair of t1 and t2 cid which match using a predicate by issuing queryContractKey repeatedly`

I’ve tried several approaches to try to implement a function that could be used in the trigger as well as called in a script to perform the tests I want, but no luck so far.  
I would kindly ask for your assistance.  
Best Regards, João Santos

---

<div class="post-metadata">

**Author:** ![a\_putkov](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/a_putkov/32/2971_2.png) [@a\_putkov](https://forum.canton.network/u/a_putkov)\
**Post date:** [January 27, 2023, 8:35pm UTC](https://forum.canton.network/t/reusing-function-implemented-in-trigger-context-in-a-script/6036/2 "2023-01-27T20:35:07Z")

</div>

I don’t believe it’s possible to use the same implementation of an impure function in a Daml Script and in a Daml Trigger. An impure function used in a Script cannot have the same signature as a function used in a Trigger.  
Let’s look at the `query` function as an example. In Daml Script and in Daml Trigger you can use a function named `query` to retrieve contracts from the ledger. But it’s not the same function. It’s two different functions implemented in two different libraries (Daml.Script and Daml.Trigger), albeit they share the same function name. The function imported from Daml.Script library has the signature  
`query: (Template t, IsParties p) => p -> Script [(ContractId t, t)]`  
And the function imported from Daml.Trigger library has the signature  
`query: (Template a, ActionTriggerAny m) => m [(ContractId a, a)]`
