Skip to main content

Exercise 4: Storage Method

After reviewing this code, you can return to Hands-On Exercise 4.

  1. Using VS Code - ObjectScript, 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)
        }
    }
    
    }
  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
            }
    
  4. Copy the new Store() method into the class at the bottom.

  5. Click the Save and Compile buttons.

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

FeedbackOpens in a new tab