How to run exerciseByKeyCommand from java side

Hello everyone,
Here are the data I have:

data DeclaredResult = DeclaredResult
id : Text
issuer : Party
pD : Party
num1 : Decimal
num2 : Decimal
deriving (Eq, Show)

template FooDetails
custodian : Party
depository : Party
issuer : Party
info : FooInfo
sHoldingCid : ContractId Holding.I
signatory custodian, issuer, depository

key (custodian, : (Party, Text)
maintainer key._1

choice Finalize : ()
    fooId : Text
    declaredResults : [DeclaredResult]
  controller custodian

Since I only have a contractKey and no contractId:
How would I call the exerciseByKeyCommand method from the Java side to activate the Finalize choice? What parameters should I send?

1 Like

You should use the CommandService.submitAndWait or CommandSubmissionService.submit and submit an ExerciseByKeyCommand.

Thank you. I will try it

If you are running Java codegen (which you absolutely should be doing), you can use FooDetails.byKey(new Tuple2<>(custodian, id)).exerciseFinalize(fooId, results) to create an Update<Unit>, which represents the command.

1 Like