Encontrar

文章
· 九月 10 阅读大约需 4 分钟

Learning ObjectScript as a New Developer: What I Wish I Knew

I joined InterSystems less than a year ago. Diving into ObjectScript and IRIS was exciting, but also full of small surprises that tripped me up at the beginning. In this article I collect the most common mistakes I, and many new colleagues, make, explain why they happen, and show concrete examples and practical fixes. My goal is to help other new developers save time and avoid the same bumps in the road.

 

1. Getting lost among system classes and where to start

The issue: ObjectScript/IRIS ships with many system classes and packages (%Library, %SYS, %Persistent, %SQL, etc.). As a new dev, it’s hard to know which class or pattern fits a task. I remember trying to find an appropriate persistent class and being unsure whether to extend %Persistent or use a registry-type class.

Why it matters: Picking the wrong approach early makes code harder to maintain and integrates poorly with IRIS features (indexes, security, SQL).

Tip: Start from the concrete need (store records? expose SQL? share objects across processes?) and then search the Class Reference for the relevant capability (persistence, indexes, collections). Use Studio or the InterSystems VS Code extension to browse classes interactively and inspect examples.

 

2. Documentation overwhelm: not knowing the right keywords

The issue: The docs are comprehensive, but if you don’t know the correct class name or term, searches return many unrelated pages. Early on I often spent a lot of time because I didn’t yet know the canonical terms.

Why it matters: You waste time and might implement suboptimal patterns.

Tip:

  • Search the Developer Community for practical examples (search by “persistent class example”, “ObjectScript transaction TSTART example”, etc.).
  • Use the VS Code InterSystems extension, it can jump directly to class definitions.
  • When searching docs, combine class names and actions: e.g. "%Persistent property index example".

 

3. Forgetting .. for local method call

The issue: Calling a method of the same class without .. results in a call not being recognized at runtime.

Wrong:

Class MyClass Extends %Persistent { 
   Method DoWork() 
   { 
       Do Hello()  // wrong: this is not a local method invocation
   } 
   Method Hello()
   { 
       Write "Hello", ! 
   } 
}

Right:

Method DoWork() {
   Do ..Hello()  // correct: local method call 
}

Tip: When you get “Unknown routine” errors for methods you see in the class, check whether you used .. for self-calls.

 

4. Confusing globals and local variables

The issue: ObjectScript distinguishes globals (persistent across sessions, e.g. ^MyGlobal) and local variables (in-memory, scope-limited). New developers frequently use one when the other is intended.

SET localVar = 10    // exists only during the current process/session
SET ^globalVar = 20  // persists in the database across processes and sessions

Tip: Use persistent classes for data that should be stored long-term. Limit use of globals to very specific low-level needs or when you understand consequences.

 

5. Hardcoding globals instead of using persistent classes

The issue: My instinct at first was “quick and dirty”: write to ^MyGlobal directly. That works, but it bypasses class-based benefits: schema, indices, SQL access, and safety.

Better approach:

Class Person Extends %Persistent 
{ 
    Property Name As %String; 
    Property DOB As %Date; 
}

Tip: Prefer %Persistent classes for application data. They give you a cleaner model and integrate with SQL and indexes.

 

6. Ignoring transactions (TSTART / TCOMMIT)

The issue: Developers sometimes perform several writes thinking they are atomic. Without explicit transaction control, partial failures can leave inconsistent data.

TSTART 
// multiple updates 
TCOMMIT

Tip: Identify logical units of work and wrap them in transactions. If something can fail halfway, use TSTART / TROLLBACK / TCOMMIT. Keep in mind that IRIS supports nested transactions: multiple TSTART calls increase the transaction level, and all levels must be committed (or rolled back) before changes are final.

 

7. Misunderstanding SQL options: Embedded SQL vs %SQL.Statement

The issue: Embedded SQL (UPDATE, SELECT blocks inside ObjectScript) and the %SQL.Statement API are both available; choosing without knowing pros/cons can cause awkward code.

Guideline: Use Embedded SQL for fixed/static queries inside routines; use %SQL.Statement when you need to build and execute SQL dynamically.

 

8. Skipping proper error handling

The issue: Not using TRY/CATCH or signaling errors properly makes debugging and reliability harder.

TRY 
{ 
   // code that may fail 
} CATCH ex 
{  
   Write "Error: ", ex.DisplayString(),! 
}

Tip: Wrap risky operations (I/O, external calls, dynamic SQL) with error handlers and log informative messages.

 

Final notes

Early on I wrote globals for convenience and later spent time refactoring to persistent classes. That refactor taught me the value of designing data models up front and using the tools IRIS provides. My best habits now: small experiments, frequent searches on Developer Community, and keeping transactions and error handling in mind from the start.

If you’re new: treat your first few tasks as experiments, create small persistent classes, try simple Embedded SQL, and use the Management Portal and VS Code browser to inspect system classes. Ask questions on the Developer Community; many others had the same “gotchas.”

For more: check the official ObjectScript documentation and the Developer Community for examples and patterns.

 

This article was reviewed and edited with the assistance of AI tools to improve clarity and grammar. The experiences and suggestions described are my own.

8 条新评论
讨论 (8)4
登录或注册以继续
公告
· 九月 10

Concurso de Lenguajes Externos de InterSystems: .Net, Java, Python, JavaScript

Hola Desarrolladores,

Nos encanta poder anunciar el nuevo concurso de programación online de InterSystems:

🏆 InterSystems External Languages Contest 🏆

Duración: del 22 de septiembre al 12 de octubre de 2025

Bolsa de premios: $12.000


De qué va

Desarrollar una aplicación que muestre el uso de Lenguajes Externos con InterSystems IRIS.

Requisitos generales:

  1. La aplicación o biblioteca debe ser completamente funcional. No debe ser una importación ni una interfaz directa de una biblioteca ya existente en otro lenguaje (excepto en C++, donde realmente se necesita mucho trabajo para crear una interfaz para IRIS). No debe ser un copia-pega de una aplicación o biblioteca existente.
  2. Aplicaciones aceptadas: apps nuevas para Open Exchange o existentes, pero con una mejora significativa. Nuestro equipo revisará todas las aplicaciones antes de aprobarlas para el concurso.
  3. La aplicación debe funcionar en IRIS Community Edition o IRIS for Health Community Edition. Ambas pueden descargarse como versiones para host (Mac, Windows) desde el sitio de evaluación, o utilizarse en forma de contenedores extraídos de InterSystems Container Registry o Community Containers: intersystemsdc/iris-community:latest o intersystemsdc/irishealth-community:latest.
  4. La aplicación debe ser de código abierto y publicarse en GitHub o GitLab.
  5. El archivo README de la aplicación debe estar en inglés, contener los pasos de instalación y contener el video de demostración y/o una descripción de cómo funciona la aplicación.
  6. Solo se permiten 3 envíos por desarrollador.

Nota: Nuestros expertos tendrán la última palabra sobre si la aplicación se aprueba para el concurso o no, basándose en los criterios de complejidad y utilidad. Su decisión es final y no está sujeta a apelación.

Premios

1. Nominación de Expertos: un jurado especialmente seleccionado determinará a los ganadores.

🥇 1er lugar - $5,000 

🥈 2do lugar - $2,500 

🥉 3er lugar - $1,000

🏅 4to lugar - $500

🏅 5to lugar - $300

🌟 6-10to lugar - $100

2. Premios de la Comunidad: aplicaciones que reciban la mayor cantidad de votos en total.

🥇 1er lugar - $1,000 

🥈 2do lugar - $600 

🥉 3er lugar - $300

🏅 4to lugar - $200

🏅 5to lugar - $100

❗ Si varios participantes obtienen el mismo número de votos, todos se consideran ganadores y el premio en efectivo se reparte entre ellos.
❗ Los premios en efectivo se otorgan solo a quienes puedan verificar su identidad. Si hay dudas, los organizadores se pondrán en contacto y solicitarán información adicional sobre los participantes.

¿Quién puede participar?

Cualquier miembro de la Comunidad de Desarrolladores, excepto los empleados de InterSystems (se permiten contratistas de ISC). ¡Cread una cuenta!

Los desarrolladores pueden formar equipo para crear una aplicación colaborativa, con un límite de 5 desarrolladores por equipo.

No olvides destacar a los miembros de tu equipo en el README de tu aplicación – perfiles de usuario de la Comunidad de Desarrolladores.

Fechas importantes

🛠 Fase de desarrollo y registro de aplicaciones:

  • 22 de septiembre de 2025 (00:00 EST): comienza el concurso.
  • 5 de octubre de 2025 (23:59 EST): fecha límite para envíos.

 Período de votación

  • 6 de octubre de 2025 (00:00 EST): Empieza la votación
  • 12 de octubre de 2025 (23:59 EST): Termina la votación

Nota: los desarrolladores pueden mejorar sus aplicaciones durante todo el período de registro y de votación.

    Recursos útiles

    ✓ Documentación:

    ✓ Aplicaciones de ejemplo:

    ✓ Para principiantes con IRIS:

    ✓ Para principiantes con ObjectScript Package Manager (IPM):

    ✓ Cómo enviar vuestra aplicación al concurso:

    ¿Necesitáis ayuda?

    Uníos al canal del concurso en el servidor de Discord de InterSystems o hablad con nosotros en los comentarios de esta publicación.

    Estamos esperando VUESTRO proyecto: uníos a nuestro maratón de código para ganar.


    Al participar en este concurso, aceptáis los términos de la competición aquí establecidos. Por favor, leedlos atentamente antes de continuar.

    讨论 (0)1
    登录或注册以继续
    讨论
    · 九月 10

    Introduction to New Memebers

    Hello Everyone,

    I’m excited to join the InterSystems Developer Community, a place where IRIS, Caché, Ensemble, HealthShare, and all things InterSystems come alive through shared knowledge and collaboration.

    A little about me,

    • I’m passionate about building efficient, integration-driven solutions, exploring ObjectScript, working with REST APIs, and diving into analytics tools like DeepSee and IntegratedML.
    • I’m here to learn from your real-world experiences, whether it’s tips on interoperability, performance tuning, or best practices across IRIS and HealthShare ecosystems.
    • I also look forward to contributing back through questions, articles, and discussions.

    I didn’t find any dedicated introduction thread, so I thought of starting this one. Hopefully this doesn’t go against any guidelines. 😊

    Looking forward to connecting, solving problems together, and growing within this amazing global developer community!

    - Rajesh

    3 条新评论
    讨论 (3)4
    登录或注册以继续
    讨论 (0)0
    登录或注册以继续
    问题
    · 九月 9

    Creating a lookup table with Data from ADT message to reference later in business rule

    I have a vendor that only wants results on patients that arrive to the ED via EMS/Ambulance.  The value I need for filtering is in the PV2;38. Some of the results requested do not allow the PV2 segment to be added to the schema in the EMR.  I was told that other orgs have used a lookup table that is populated with the PV1;19 value when an ADT messages that meets the criteria is sent in.  This table is then referenced in the business rule for the results that do not have PV2;38 and if Encounter number from result message exists on the Table, the result is sent.  Has anyone done this before?  

    Documentation I found suggests copying the EnsLib.Hl7.SearchTable.  Is this the correct route to take?  

    Appreciate any feedback or instructions.  

    Thanks!

    Gigi La Course

    1 条新评论
    讨论 (1)2
    登录或注册以继续