Daml Finance - InstrumentQuantity : How to access sub parameters like, unit, quantity etc
App Development2 posts197 viewsLast activity Mar 2023
AS
Ashok_RajOP
Mar 2023In Daml finance, InstrumentQuantity is a common type that’s used for capturing both the unit and amount, like in case of issuance request to specify the requested quantity. I want to use a variable of that type in a service and make checks like if the requested quantity is above a certain value. I tried the following.
CreateAuditedIssuanceRequest{id; description; account; quantity; quantityAudited} <- fetchAndArchive createAuditedIssuanceRequestCid
assert quantity.amount > quantityAudited.amount
assert quantity.unit.id == quantityAudited.unit.id
assert quantity.amount > 100
assert quantity >100
both quantityAudited and quantity are of type InstrumentQuantity.
I got a lot of errors related to trying to access nonexistent field. and type mismatch. Can you point me in the right direction
MA
Matteo_Limberto
Mar 2023Hi @Ashok_Raj,
I believe it should be
assert $ quantity.amount > 100.0
given that
amountis of typeDecimalrather thanInt- we need to evaluate the predicate before we call
assert, hence the$operator