Scenario : Ambiguous Occurrence Error
- Arvind_RaoOP 2
Mod note: As of SDK 1.5.0 Scenarios have been superseded by the more powerful Daml Script. We now recommend using that for all purposes. For more information, and to learn how to use Script please check out @Andreas’ post on our blog.
Hi Team, I am running into the following issue while trying to setup the initialization script
Message: daml\Main.daml:212:64: error: Ambiguous occurrence ΓÇÿoperatorΓÇÖ It could refer to either the field ΓÇÿoperatorΓÇÖ, defined at daml\Main.daml:143:5 or the field ΓÇÿoperatorΓÇÖ, defined at daml\Main.daml:127:5 or the field ΓÇÿoperatorΓÇÖ, defined at daml\Main.daml:82:5 or the field ΓÇÿoperatorΓÇÖ, defined at daml\Main.daml:71:5 or the field ΓÇÿoperatorΓÇÖ, defined at daml\Main.daml:64:5 or the field ΓÇÿoperatorΓÇÖ, defined at daml\Main.daml:39:5 ERROR: Creation of DAR file failed. DAML Code : -- Product data Product = Product with productId: Text productName: Text modelNumber: Text productDetails : Text productURL : Text deriving (Eq, Show) -- The System template Network with operator : Party where signatory operator controller operator can nonconsuming CreateProductCard : ContractId ProductCard -- persist/not single use as need multiple with product : Product do create ProductCard with product, operator -- ProductCard template ProductCard with product : Product operator : Party where signatory operator -- Initialization Script setup : Script () setup = do let product1 = Product with productId = "" productName = "" modelNumber = "" productDetails = "" productURL = "" operator1 <- allocatePartyWithHint "Operator" $ PartyIdHint with partyIdHint = "Operator" network1 <- submit operator1 do createCmd Network with operator = operator1 submit operator1 do exercise network1 CreateProductCard with operator = operator1; product = product1 pure() - cocreature 3
Hi @Arvind_Rao, welcome to the DAML discourse forum!
There are two issues here:
First, you are trying to add an
operatorfield toCreateProductCardbut if you look at the definition of the choice it only has aproductfield. The error message here is a bit confusing since you have other fields calledoperator, e.g., the one inProductCard, so the rather than an error thatCreateProductCarddoes not have that field, the DAML Compiler gets confused and thinks you might mean one of the others but none fit. The solution there is rather simple: Simply remove the field.The other issue is that you are using
exercisein the argument you pass tosubmit. This works in scenarios but in DAML Script you have to useexerciseCmd. So the fixed line looks as follows:submit operator1 do exerciseCmd network1 CreateProductCard with product = product1 - Arvind_Rao 1
Ah, thank you !!!
- Arvind_Rao
cocreature:operator
But is’int the “operator” passed from the Network to the “CreateProductCard” choice implicitly? If not how do I pass it to the ProductCard template (so it knows who/created it?)
- cocreature 3
I wouldn’t call it “passed implicitly”. Inside the body of a choice you have access to both the fields of a template and the fields of the choice argument. For the
CreateProductCardchoice that means you have access to theoperatorfield from the and theproductfield from the choice argument. When you callexerciseorexerciseCmdyou pass in the contract id and the choice argument so in your examplenetwork1is the contract id and your choice argument isCreateProductCard with product = product1. The ledger will fetch the contract associated with the contract id and that’s where theoperatorcomes from in the choice body. - Arvind_Rao
Thanks, that makes sense !!!