Skip to content
Discussions/App Development/Make fields nested inside a data type from template parameters available for autowiring/autobinding in choice scopeForum ↗

Make fields nested inside a data type from template parameters available for autowiring/autobinding in choice scope

App Development5 posts474 views7 likesLast activity Aug 2021
ME
meetOP
Aug 2021
template LoanApproval
  with
    loanApplication: LoanApplication
    loanTerms: LoanTerms
  where 
    signatory loanApplication.bank
    controller loanApplication.customer can 
      SignAgreement: ContractId LoanAgreement
        do create LoanAgreement with ..

Is it possible to use the LoanApplication {..} syntax to make the fields inside loanApplication directly available in the choice scope for “autowiring” at do create SignHirePurchaseAgreement with .. ?

LE
Leonid_Rozenberg
Aug 2021

In the choice body

let LoanApplication { .. } = loanApplication
ME
meet
Aug 2021

Thank you!

LE
Leonid_Rozenberg
Aug 2021

Just remember that with great power comes great responsibility.

There’s a little devil (or is it an angel) that nags at me when I use this syntax as it can do so much work that I might not notice when it does too much.

ST
Stephen
Aug 2021

TBQH it is less devilish than .. in record-creation; introducing a bunch of bindings seems much less scary to me than automatically using whatever bindings are laying around. Certainly one of the unstated reasons I posted about using records more was to encourage a Daml style that wouldn’t lean so heavily on .. record creation.

Then again I come from the “DI is useless, just pass arguments to a function” school of thought.

@meet On a more serious note, if the same set of fields happens to be used in several places, it may be clearer to factor that set of fields to a record, and then pass it explicitly. Of course that totally depends on the other code details not seen here.

← Back to Discussions