docs.intersystems.com
Home  /  Application Development: Core Topics  /  ObjectScript Tutorial  /  Exercise 4: Storage Method


ObjectScript Tutorial
Exercise 4: Storage Method
[Back]  [Next] 
InterSystems: The power behind what matters   
Search:  


Click here to return to the exercise description in the main part of the tutorial.
  1. 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 from here into the class at the very end.
  5. Click the Save and Compile buttons.
  6. Start Terminal, and run your method, by typing do ##class(ObjectScript.DataEntry4).Main().