I keep on wanting to exercise a choice from another choice (for the same template). Is there a way to do this without knowing the contract id? i.e. I can't call exercise ??? MyChoice
from the body of another choice, without knowing ???
. Or am I trying to do something fundamentally wrong? Ideally something like exercise this.id MyChoice

- 2,388
- 1
- 22
- 33
2 Answers
There is an implicit variable self
which is the contract ID of this
given to every choice. So for example,
nonconsuming choice NoConsume : Int
controller p
do return 41
postconsuming choice PostConsume : Int
controller p
do (+2) <$> exercise self NoConsume -- Yes, fetching self in a postconsuming choice is ok.

- 67
- 3
From an internal DA conversation:
moritz.kiefer 9 days ago exercise self MyChoice works iirc?
andrae.muys 9 days ago self was introduced for precisely this purpose. Be aware that the contract will be archived before your choice exercises in consuming choices. You need to use a post-consuming or non-consuming choice to avoid this.
Luciano 9 days ago Is postconsuming documented? I don't recall seeing it.
moritz.kiefer 9 days ago https://docs.daml.com/concepts/glossary.html#postconsuming-choice there is also a blogpost somewhere iirc
moritz.kiefer 9 days ago Found it https://blog.daml.com/daml-driven/daml-choice-annotations blog.daml.comblog.daml.com DAML choice annotations This post reviews the consuming concept and explains the meaning of the newly added preconsuming and postconsuming keywords.