Skip to content
Discussions/App Development/How to run exerciseByKeyCommand from java sideForum ↗

How to run exerciseByKeyCommand from java side

App Development4 posts243 views2 likesLast activity Jan 2023
RO
ronihOP
Jan 2023

Hello everyone,
Here are the data I have:

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

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

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

choice Finalize : ()
  with
    fooId : Text
    declaredResults : [DeclaredResult]
  controller custodian
    do
     …..

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?

ST
stefanobaghino-da
Jan 2023

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

RO
ronih
Jan 2023

@stefanobaghino-da
Thank you. I will try it

ST
Stephen
Jan 2023

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.

← Back to Discussions