Skip to content
CCPEDIAby Unity Nodes
App Development

Daml Finance - InstrumentQuantity : How to access sub parameters like, unit, quantity etc

2 posts220 viewsLast activity Mar 2023

  1. Ashok_RajOP

    In 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

  2. Matteo_Limberto

    Hi @Ashok_Raj,

    I believe it should be

    Ashok_Raj:
            assert $ quantity.amount > 100.0
    

    given that

    • amount is of type Decimal rather than Int
    • we need to evaluate the predicate before we call assert, hence the $ operator