Using find_active on templates with Data types
- Luis_AlmeidaOP
Hello,
I am trying to use dazl to query the ledger for Order contracts. If no filters are applied, I can retrieve all the contracts using the find_active function from the AIOPartyClient.
I have tried to look for examples of filters but didn’t encounter any that filtered using data types, only primitive fields.
How can I use find_active to filter using a field from a data type inside the template?
For example, for the Order template in Daml MiB:template Order with operator : Party provider : Party customer : Party status : Status details : Details providerOrderId : Optional Text executions : [Execution] remainingQuantity : Decimal createdAt : TimeWhich has the Details data type:
data Details = Details with id : Text listingId : Text asset : Asset side : Side orderType : OrderType timeInForce : TimeInForce marketType : MarketType optExchangeFee : Optional (ContractId AssetDeposit) deriving (Eq, Show)How can I use find_active to get all orders by their details.id?
Thank you in advance.
- dtanabe
You should be able to do
client.find_active(template_id, { "details": { "id": some_value } }); for Pythondict's, they’re considered matching if a subset of the fields match. - Luis_Almeida
Hello, I have tried doing so and I always get empty results. I know the orders exist because I can see them on the navigator and if I find without filters. Do you know what could be the problem?
Thank you. - dtanabe
hmm perhaps there is a bug then—another way of doing this is
client.find_active(template_id, lambda cdata: cdata["details"]["id"] == some_value)but in the meantime, I’ll look the possible (probable) bug. - Luis_Almeida 1
I found the problem. I thought the variable I was supplying for the filter was a String but it was actually an Int. It worked now.
Thank you.