Scenario : Ambiguous Occurrence Error
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()
Hi @Arvind_Rao, welcome to the DAML discourse forum!
There are two issues here:
First, you are trying to add an operator field to CreateProductCard but if you look at the definition of the choice it only has a product field. The error message here is a bit confusing since you have other fields called operator, e.g., the one in ProductCard, so the rather than an error that CreateProductCard does 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 exercise in the argument you pass to submit. This works in scenarios but in DAML Script you have to use exerciseCmd. So the fixed line looks as follows:
submit operator1 do exerciseCmd network1 CreateProductCard with product = product1
Ah, thank you !!!
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?)
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 CreateProductCard choice that means you have access to the operator field from the and the product field from the choice argument. When you call exercise or exerciseCmd you pass in the contract id and the choice argument so in your example network1 is the contract id and your choice argument is CreateProductCard with product = product1. The ledger will fetch the contract associated with the contract id and that’s where the operator comes from in the choice body.
Thanks, that makes sense !!!