Pulling out data from multiple contract


I am trying to get data from the previously created multiple contracts within a template and combine partial dataset from each contract to make one final dataset. How can i achieve this in daml?

– contract already created, in ledger

template CombineDataSet

cID1 ← @ContractA2E
cID2 ← @ContractF2J
cID3 ← @ContractK2O
and pull A,B from @ContractA2E; G,H from @ContractF2J; M,N,O from @ContractK2O - concat and store it in finalDataSet

Does daml samples have any such template snippet/use case reference to achieve this?

1 Like

You can lookup a contract on the ledger if you have its contract ID, or the contract has a key and you have that key, and you are a stakeholder in the contract.

However, most workflows that build up a final contract like your CombineDataSet are linear and cumulative, meaning they carry along the data from each preceding step, and each template has a choice that accepts additional data and takes you to the next step. The new Daml training videos feature several examples of this.

If that does not fit your use case, contract IDs may be passed as choice arguments; this is the easiest way for you to get at the contracts you want to combine, but it is worth asking yourself: what do you want to happen to the prior contracts then?