Exercise 4: Storage Method
Click here to return to the exercise description in the main part of the tutorial.
-
Using VS Code - ObjectScript, change the top line of ObjectScript.DataEntry3 to ObjectScript.DataEntry4, and save it as ObjectScript.DataEntry4.
-
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) } } }
-
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 the new Store() method from here into the class at the very end.
-
Click the Save and Compile buttons.
-
Start the Terminal, and run your method, by typing do ##class(ObjectScript.DataEntry4).Main().