Skip to main content
Previous sectionNext section

Exercise 4: Storage Method

Click here to return to the exercise description in the main part of the tutorial.

  1. Using Atelier, change the top line of ObjectScript.DataEntry3 to ObjectScript.DataEntry4, and save it as ObjectScript.DataEntry4.

  2. Edit Main() so that it calls Store() after calling Display(), also passing answers.

    Class ObjectScript.DataEntry3
    /// Main loop section
    ClassMethod Main()     
        while ..Prompt(.answers) {       
            do ..Display(answers)
            do ..Store(answers)
    Copy code to clipboard
  3. In ValidPhone(), just after the line that adds the default area code, add an If that uses $Data to check if the phone exists in the index already; if it does, return 0.

            set:($match(phone, "\d{3}-\d{4}")) phone = "617-" _ phone  // add default area code
            // is phone already taken?
            if $data(^PersonI("Phone", phone)) {
                write !, "Phone number already in use"
                return 0
    Copy code to clipboard
  4. Copy the new Store() method from here into the class at the very end.

  5. Click the Save and Compile buttons.

  6. Start the Terminal, and run your method, by typing do ##class(ObjectScript.DataEntry4).Main().