# How to avoid command deduplication in DAML Trigger

**URL:** <https://forum.canton.network/t/how-to-avoid-command-deduplication-in-daml-trigger/5232>\
**Category:** App Development\
**Created:** [September 15, 2022, 7:09pm UTC](https://forum.canton.network/t/how-to-avoid-command-deduplication-in-daml-trigger/5232 "2022-09-15T19:09:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pris17](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/pris17/32/2078_2.png) [@Pris17](https://forum.canton.network/u/Pris17)\
**Post date:** [September 15, 2022, 7:09pm UTC](https://forum.canton.network/t/how-to-avoid-command-deduplication-in-daml-trigger/5232/1 "2022-09-15T19:09:30Z")

</div>

@cocreature @bernhard How to mark some other contract other than TestTrigger as pending while exercising choice on TestTrigger.

Scenario is: I query ACS of ContractA and based on one of the ContractA value, I will then exercise a choice on ContractB.  
Here I want to mark ContractA as pending until choice on ContractB is completed.  
How to achieve this?

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [September 15, 2022, 7:19pm UTC](https://forum.canton.network/t/how-to-avoid-command-deduplication-in-daml-trigger/5232/2 "2022-09-15T19:19:28Z")

</div>

To do that type of stuff you need to use [`emitCommands`](https://docs.daml.com/triggers/api/Daml-Trigger.html#function-daml-trigger-emitcommands-47366) instead of the more specific `dedupExercise`. That accept two arguments: The commands you want to submit and the contracts you want to mark as pending. So you can do things like:

```haskell
emitCommands [exerciseCmd cid1 Choice] [toAnyContractId cid2]

```

to exercise a choice on cid1 but mark cid2 as pending

---

<div class="post-metadata">

**Author:** ![Pris17](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/pris17/32/2078_2.png) [@Pris17](https://forum.canton.network/u/Pris17)\
**Post date:** [September 15, 2022, 7:37pm UTC](https://forum.canton.network/t/how-to-avoid-command-deduplication-in-daml-trigger/5232/3 "2022-09-15T19:37:41Z")

</div>

Got it.

And until when will be the cid2 in pending state?

Also if I have list of cid2 then how to add it in emitCommand?

Thanks

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [September 15, 2022, 7:54pm UTC](https://forum.canton.network/t/how-to-avoid-command-deduplication-in-daml-trigger/5232/4 "2022-09-15T19:54:53Z")

</div>

> [@Pris17](#):
>
> And until when will be the cid2 in pending state?

Until either the command succeeds and your trigger has processed the resulting transaction or the command fails.

> Also if I have list of cid2 then how to add it in emitCommand?

The second argument is a list, so you can do `emitCommands [exerciseCmd … _] (map toAnyContractId cid2s)`

---

<div class="post-metadata">

**Author:** ![Pris17](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/pris17/32/2078_2.png) [@Pris17](https://forum.canton.network/u/Pris17)\
**Post date:** [September 16, 2022, 4:12am UTC](https://forum.canton.network/t/how-to-avoid-command-deduplication-in-daml-trigger/5232/5 "2022-09-16T04:12:20Z")

</div>

@cocreature I don’t see the same behavior in my case. I have done exactly as you suggested but it doesn’t avoid command deduplication. What are other ways to handle this?

Thanks

---

<div class="post-metadata">

**Author:** ![Pris17](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/pris17/32/2078_2.png) [@Pris17](https://forum.canton.network/u/Pris17)\
**Post date:** [September 16, 2022, 4:13am UTC](https://forum.canton.network/t/how-to-avoid-command-deduplication-in-daml-trigger/5232/6 "2022-09-16T04:13:59Z")

</div>

Also, is there a way that I can add 2 contract ids of 2 different contracts in toAnyContractId?  
@cocreature@bernhard @Gary_Verhaegen

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [September 16, 2022, 6:47am UTC](https://forum.canton.network/t/how-to-avoid-command-deduplication-in-daml-trigger/5232/7 "2022-09-16T06:47:25Z")

</div>

> [@Pris17](#):
>
> I don’t see the same behavior in my case. I have done exactly as you suggested but it doesn’t avoid command deduplication. What are other ways to handle this?

Could you expand on that? What exactly do you have in your code now and what are you observing?

> Also, is there a way that I can add 2 contract ids of 2 different contracts in toAnyContractId?

something like `[toAnyContractId cid1, toAnyContractId cid2]` works. You cannot use `map` in that case because the list before mapping would have contract ids of different types which is not possible in Daml. List elements always need to have the same type.

---

<div class="post-metadata">

**Author:** ![Pris17](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/pris17/32/2078_2.png) [@Pris17](https://forum.canton.network/u/Pris17)\
**Post date:** [September 16, 2022, 7:23am UTC](https://forum.canton.network/t/how-to-avoid-command-deduplication-in-daml-trigger/5232/8 "2022-09-16T07:23:43Z")

</div>

Got it
