Error Not in Sope: Parties

I am experimenting with the following script

daml 1.2
module ScriptExample where
import Daml.Script
import Main
data LedgerParties =LedgerParties with
    operator : Party
    alice : Party 
    atriumhealth : Party
 
initialize : LedgerParties -> Script ()
initialize parties = do

    Network <- submit parties.operator do createCmd Network with parties.operator
    HealthClinicInvitation <- submit parties.operator do exerciseCmd Network InviteHealthClinic with parties.atriumhealth

    pure ()

I am encountering the following error on line 13 with the second parties.operator

{ScriptExample.daml:18:66: error:\n    Not in scope: ‘parties’",
	"source": "typecheck",
	"startLineNumber": 18,
	"startColumn": 66,
	"endLineNumber": 18,
	"endColumn": 73
}

Any suggestions on how to resolve this ?

Hi Bart, there are two issues here:

  1. You need to supply the field name when using with. So Network with operator = parties.operator. There is one special case if your field name and the variable you want to set it to have the same name, Then you could just say Network with operator which is equivalent to Network with operator = operator. However in your case the value is not just a variable but parties.operator so you have to specify them separately or it tries to interpret parties as the field name.
  2. What you get back from submit … (createCmd …) is a contract id not the template itself. So matching it against Network isn’t going to work (and you are missing an argument). Instead just bind it to a variable
  networkCid <- submit parties.operator $ do createCmd Network with operator = parties.operator

Note that variables are always lowercase while data constructors are always upper case.
Same for the second line:

  healthClinicCid <- submit parties.operator do exerciseCmd networkCid InviteHealthClinic with healthclinic = parties.atriumhealth

Putting things together the fixed version of your example looks as follows:

initialize : LedgerParties -> Script ()
initialize parties = do
    networkCid <- submit parties.operator do createCmd Network with operator = parties.operator
    healthClinicCid <- submit parties.operator do exerciseCmd networkCid InviteHealthClinic with healthclinic = parties.atriumhealth
    pure ()
2 Likes

Thanks for the clarifications ! Appreciate it