# T.dedupCreate, parse Error

**URL:** <https://forum.canton.network/t/t-dedupcreate-parse-error/4298>\
**Category:** App Development\
**Tags:** trigger, damlhub\
**Created:** [April 11, 2022, 6:39am UTC](https://forum.canton.network/t/t-dedupcreate-parse-error/4298 "2022-04-11T06:39:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rikotacards](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@rikotacards](https://forum.canton.network/u/rikotacards)\
**Post date:** [April 11, 2022, 6:39am UTC](https://forum.canton.network/t/t-dedupcreate-parse-error/4298/1 "2022-04-11T06:39:53Z")

</div>

![Screenshot 2022-04-10 at 11.35.38 PM](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/a/a474067b6c0f2da9837d5e6606dcbc4d9029088e.png)  
Full Code, I get an error with the T.dedupCreate portion, and I can’t seem to figure out why. Any ideas? I can’t tell if its an indentation issue, or if I’m using `T.dedupCreate` incorrectly.

also the documentation, below, doesn’t specify where I’m supposed to place the arguments of a choice? or am I misreading this.

dedupCreate : (Eq t, Template t) =\> t → TriggerA ()  
Create the template if it’s not already in the list of commands in flight (it will still be created if  
it is in the ACS).  
Note that this will send the create as a single-command transaction. If you need to send multiple command

```haskell
acceptSwapTrigger: T.Trigger ()
acceptSwapTrigger = T.Trigger 
 { initialize = pure (),
  updateState = \_ -> pure (),
  registeredTemplates = T.RegisteredTemplates [T.registeredTemplate @Trade, T.registeredTemplate @AssetHoldingAccount, T.registeredTemplate @TransferPreApproval],
  rule = \p -> do
    tradeRequests <- T.query @Trade
    let isMe = (\tradeRequests -> tradeRequests.receiver == p)
    let meList = filter (\(_, contract) -> isMe contract) tradeRequests

    debug ("asset holding account invites", meList)

    
    unless ( DA.Foldable.null meList ) do 
      case meList of 
        [] -> pure ()

        (cid, c) :: _ -> do
          optOfferedAsset <- T.queryContractId c.offeredAssetCid
          transferPreApproval <- T.queryContractId c.requestedAssetsTxPreApprovalCid
          whenSome optOfferedAsset $ \m -> do
            asset <- T.dedupCreate @Asset with 
              assetType = transferPreApproval.asset.assetType, 
              amount = transferPreApproval.asset.amount, 
              owner = p 
            txApproval <- T.dedupExerciseByKey @AssetHoldingAccount (m.asset.assetType, p) Preapprove_Transfer_In with asset = m.asset
            T.dedupExercise c Trade_Settle with 
              requestedAssetCid = asset
              offeredTxPreApprovalCid = txApproval

      
    debug $ "TRIGGERED",
  heartbeat = None
}

```

---

<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:** [April 11, 2022, 6:44am UTC](https://forum.canton.network/t/t-dedupcreate-parse-error/4298/2 "2022-04-11T06:44:36Z")

</div>

`dedupCreate` accepts the contract argument and then sends a command to create that contract. You are specifying the type (via `@Asset`) but you’re missing the constructor of the record (which is not prefixed with `@`).

```haskell
T.dedupCreate @Asset Asset with
  assetType = …
  amount = …
  owner = …

```

should do the trick. However, the type argument can be inferred so you can also omit it and shorten it to

```haskell
T.dedupCreate Asset with
  assetType = …

```

As for your question on choice arguments, `dedupCreate` does not exercise a choice so there is no choice argument. If you want to exercise a choice look at `exerciseCmd` and `dedupExercise`.

---

<div class="post-metadata">

**Author:** ![rikotacards](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@rikotacards](https://forum.canton.network/u/rikotacards)\
**Post date:** [April 11, 2022, 7:11am UTC](https://forum.canton.network/t/t-dedupcreate-parse-error/4298/3 "2022-04-11T07:11:39Z")

</div>

Thanks for the response!

I also know what i’m doing here below is wrong.  
What I want to do is either create the contract, and capture the value, and use it as an argument later.

Or exercise a choice, and capture the return value, and use that as an argument. However, T.dedupeCreate, or T.ExerciseByKey both don’t return a value.

Does `exerciseCmd` work in a trigger? That seems to only work in Daml scripts?  
`asset <- T.dedupCreate @Asset with assetType = transferPreApproval.asset.assetType, amount = transferPreApproval.asset.amount, owner = p txApproval <- T.dedupExerciseByKey @AssetHoldingAccount (m.asset.assetType, p) Preapprove_Transfer_In with asset = m.asset T.dedupExercise c Trade_Settle with requestedAssetCid = asset offeredTxPreApprovalCid = txApproval`

---

<div class="post-metadata">

**Author:** ![rikotacards](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@rikotacards](https://forum.canton.network/u/rikotacards)\
**Post date:** [April 11, 2022, 7:15am UTC](https://forum.canton.network/t/t-dedupcreate-parse-error/4298/4 "2022-04-11T07:15:14Z")

</div>

![Screenshot 2022-04-11 at 12.14.25 AM](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/b/baf936524f4019174ffb0de5ff7fd87ba62f42c4.png)  
And why are these argument fields “ambiguous” now…

---

<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:** [April 11, 2022, 8:37am UTC](https://forum.canton.network/t/t-dedupcreate-parse-error/4298/5 "2022-04-11T08:37:04Z")

</div>

> What I want to do is either create the contract, and capture the value, and use it as an argument later.
> 
> Or exercise a choice, and capture the return value, and use that as an argument.

You say you want to do either or but your current code does both. In which case do you want to create and in which case do you want to exercise?

> However, T.dedupeCreate, or T.ExerciseByKey both don’t return a value.

Command submissions in triggers are always asynchronous so you don’t get a result. However, you can observe the effect of submitting the transaction later as part of a change to the ACS, e.g., if you submit a create the contract will be in the ACS later (assuming it succeeded). What return value are you looking for?

> And why are these argument fields “ambiguous” now…

That error often happens if the type has no field with that value. Can you share the definition of `Asset`?

> Does `exerciseCmd` work in a trigger? That seems to only work in Daml scripts?

You can use `exerciseCmd` in the list of commands you pass to `emitCommands`. But it’s a case of either use `dedupExercise` or use `emitCommands` + `exerciseCmd` not both.
