Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I had to put a $get #3

Open
driftingprogrammer opened this issue Aug 20, 2021 · 2 comments
Open

I had to put a $get #3

driftingprogrammer opened this issue Aug 20, 2021 · 2 comments
Assignees

Comments

@driftingprogrammer
Copy link

driftingprogrammer commented Aug 20, 2021

While playing around and trying to use the iterate function with the global ^Settings on https://gettingstarted.intersystems.com/language-quickstarts/objectscript-quickstart/ I was getting an error, and using the $get function on line 20 fixed it for me. Would it not be a good practise to use the $get function on line 20 of ObjectScript.cls anyways.

Thanks.

@bdeboe
Copy link

bdeboe commented Aug 24, 2021

Thanks for bringing this up. The current code sample is meant as a simple illustration, but indeed you can trip over this error if there is an additional subscript (which dwells just a little outside of the sample scenario).

Assigning to @isc-mlo who owns this part of the documentation for his consideration.

@isc-solon
Copy link
Contributor

To other developers that are learning ObjectScript and reading this: we don't want to teach anyone to "use the $get function everywhere, just to be safe." In this QuickStart:

  • Using $get is not necessary when calling the Iterate() method as it is written, since it's looping through ^testglobal..
  • Changing Iterate() to loop through the ^Settings global is a fine thing to try. Typically, a global with multiple levels of subscripts would be traversed using nested $order loops, one per level (which as @bdeboe said, is beyond the focus of this QuickStart). When looping through only the first level of ^Settings, using $get will prevent the <UNDEFINED> error for the "Auto1" and "Auto2" subscripts. Or, do the following in the Web Terminal and run Iterate() without the $get:
    set ^Settings("Auto1") = "Mustang", ^Settings("Auto2") = "Charger"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants