Skip to content
Discussions/App Development/Choice : Archive current contractForum ↗

Choice : Archive current contract

App Development6 posts298 views7 likesLast activity Jul 2022
PR
prajwalhegde3OP
Jul 2022

Hi Everyone,

I have been trying to create a choice where “signatory” party/s can exercise a choice on a specific contract to archive it.

choice Archive_Contract : ()
      controller signatory
      do
        exercise [...] Archive

I guess, I have to pass the current contractId instead of […]. Not sure if this is the right approach but I tried passing it as “this.ContractId” , but seems like its giving me a error.

Can anyone help me with the correct syntax.

Thank you!

RI
rikotacards
Jul 2022

A contract is archived by default once a choice is exercised. Assuming you don’t have the nonconsuming keyword in front of the choice, you don’t need to perform anything. You can just return (),

more about nonconsuming here
https://docs.daml.com/daml/reference/choices.html#non-consuming-choices

PR
prajwalhegde3
Jul 2022

Thank you @rikotacards

CO
cocreature
Jul 2022

Once you’ve changed it to a non-consuming choice, you can use self to get access to the contract id of the current contract.

PR
prajwalhegde3
Jul 2022

Thank you @cocreature

I do have one more question though…

As per the DAML documentation Archive choice is implicitly added to every template.

Currently I have a Java GRPC method to invoke other choices defined in the template using the “CommandServiceGrpc” stub, so wanted to know if we can invoke this Archive choice from the same as well.

Ref:
https://docs.daml.com/daml/intro/4_Transformations.html#the-archive-choice

Thank you!!

CO
cocreature
Jul 2022

The choice is implicitly added by the compiler. So in Daml-LF it always exists and it’s available over the ledger API. The Java codegen should generate it for you like any other choice. If you don’t use the codegen, just call the choice called Archive.

← Back to Discussions