How To Format Non-Text Types In Let Statement Using Daml.Script

@SteveSeow gave me some good advice this morning about the use of Scripts to test Templates (I have not been doing it), and showed me how to use a Let statement block with Types parsed in from one of the custom Record Types :+1:t2: :grinning:

I have had good success so far, until the following Types.

With a Let block statement of:

let patientX = PatientSummary
        with
        consultingRooms = "Yes",
          patientName = "Michael",
          patientCode = "10001",
          patientGender = "Male",
          dateOfConsult = "2021-09-26",
          consultNotes = "Michael is not well"

Relevant Record Type:

data PatientSummary = PatientSummary -- Patient extract Medical CMS
  with
    consultingRooms : Bool <- Fail
    patientName : Text <- OK
    patientCode : Int <- Fail
    patientGender : Text <- OK
    dateOfConsult : Date <- Fail
    consultNotes : Text
  deriving (Eq, Show)

However if all Types are designated as Text, the Script will run.

consultingRooms : Text
patientName : Text
patientCode : Text
patientGender : Text
dateOfConsult : Text
consultNotes : Text

Is there a solution to this, or for the sake of a Write-Once, Execute-Many Script, is this a non-issue?

1 Like

The reference for Daml types can be found here: Reference: data types — Daml SDK 1.17.1 documentation

Generally, only strings should have double quotes, so in your example:

import DA.Date -- required for using the date function below


let patientX = PatientSummary
      with
          consultingRooms = True,
          patientName = "Michael",
          patientCode = 10001,
          patientGender = "Male",
          dateOfConsult = date 2021 Sep 26,
          consultNotes = "Michael is not well"
2 Likes

Thank you for that, it fixed the formatting and errors immediately.

I just realised that I had not seen import DA.Date, fixed :man_facepalming:t2:

2 Likes