Pesquisar

Artigo
· Ago. 18 3min de leitura

Practical ObjectScript Coding: From JSON to Globals to SQL

While starting with Intersystems IRIS or Cache, developers often encounter three core concepts: Dynamic Objects, Globals & Relational Table. Each has its role in building scalable and maintainable solutions. In this article, we'll walk through practical code examples, highlight best practices, and show how these concepts tie together. 

1. Working with Dynamic Objects:

Dynamic objects (%DynamicObject and %DynamicArray) allow developers to manipulate JSON-like structures directly in Objectscript. They are especially useful for modern applications that need to parse, transform or generate JSON.

Example: Creating & Manipulating Dynamic Objects

    // Create a Dynamic object
    Set obj - {}

    // Add properties
    Set obj.name = "Vachan"
    Set obj.age = 25
    // Nested objects
    Set obj.address = {"city":"Bengaluru", "zip":"560000"}
    
    // Add an Array
    Set obj.skills = ["Objectscript", "SQL"]
    
    // Convert to JSON string
    Set json = obj.%ToJSON()
    Write json,!
    
    // Parse JSON string back to an object
    Set parser = {}.%FromJSON(json)
    Write parser.name

Best Practices:

  • Always validate JSON input with %FromJSON() to catch errors.
  • Use obj.%Get("property") when unsure if a property exists.
  • Favor %DynamicArray for list-like structures.

2. Using Globals Effectively:

Globals are hierarchical sparse arrays stored directly in the IRIS database engine. They are extremely fast and can store virtually any structure.

Example: Storing Data in Globals

// Store student data in a global
SET ^Student(1,"Name") = "Alice"
SET ^Student(1,"Age") = 29
SET ^Student(2,"Name") = "Bob"
SET ^Student(2,"Age") = 34
// Retrieve data
WRITE ^Student(1,"Name")  // outputs: Alice
// Iterate over all students
SET id=""
FOR  SET id=$ORDER(^Student(id)) QUIT:id=""  {
    WRITE "Student ",id,": ",^Student(id,"Name")," (Age ",^Student(id,"Age"),")",!
}

Best Practices:

  • Define a clear global structure before coding (avoid ad-hoc keys).
  • Use globals for high-performance storage when SQL overhead is not needed.
  • For application data, prefer persistent classes with globals managed under the hood.

3. Creating Relational SQL tables:

In IRIS, relational tables can be created using both SQL DDL and persistent classes.

Example: Creating a SQL Table via DDL

CREATE TABLE Employee (
    ID SERIAL PRIMARY KEY,
    Name VARCHAR(50),
    Age INT,
    Department VARCHAR(50)
);

Example: Creating the same table as a Persistent Class

Class Company.Employee Extends (%Persistent) {
    Property Name As %String(MAXLEN=50);
    Property Age As %Integer;
    Property Department As %String(MAXLEN=50);
}

Once compiled, this class automatically creates an underlying global and an SQL table. You can now use both ObjectScript and SQL:

// Create and save an employee
SET emp = ##class(Company.Employee).%New()
SET emp.Name = "Charlie"
SET emp.Age = 40
SET emp.Department = "IT"
DO emp.%Save()

// Query employees with SQL
&sql(SELECT Name, Age FROM Company.Employee)
WHILE (SQLCODE=0) {
    WRITE "Employee: ",Name,", Age: ",Age,!
    FETCH NEXT
}

Best Practices:

  • Prefer persistent classes for maintainable applications.
  • Use SQL DDL for quick table definitions or integration with external systems.
  • Always define indexes for commonly queried properties.

 

SUMMARY:

Whether you are parsing JSON payloads, managing high-speed lookup data, or designing relational tables, understanding when to use dynamic objects, globals, or persistent classes is key to becoming an effective ObjectScript developer.

2 Comments
Discussão (2)1
Entre ou crie uma conta para continuar
InterSystems Oficial
· Ago. 17

InterSystems サポートプラットフォーム最新情報 Q3-2025

2025年第3四半期の最新情報をお伝えします。

3か月前の前回にご案内した重要なお知らせを、ここであらためて振り返ってみましょう。

  • IRIS 2025.1 で RHEL 10 サポートが追加されました。
  • 2025.3 では、すべてのオペレーティングシステムで OpenSSL 3 が使用されます。SUSE 15 sp6 は、SUSEを利用する IRISユーザのミニマムサポート OS となります。
  • ミニマムサポート CPU の基準が 2025.3 で引き上げられます。
  • 古い Windows Server オペレーティングシステム は 2025.3 でサポート対象外となります。

初めてご覧になる方、はじめまして!この記事では、最近おこなわれた変更点や今後予定されている変更点に関する情報を、みなさまに共有させていただきます。ただ、将来の予測は難しい側面があり、ロードマップは約束されたものではないということを十分ご理解くださいませ。   

 

InterSystems IRIS 本番環境用オペレーティングシステムと CPU アーキテクチャ

ミニマムサポート CPU アーキテクチャ

2024年、インターシステムズは、IRIS をより早くするために新しい CPU 命令を利用できるよう、すべての Intel および AMD ベースのサーバに関する ミニマムサポート CPU モデルを発表しました。IRIS 2025.3 ではこのリストが更新され、AVX、AVX2、BMI、BMI2 命令を利用する x86-64-v3 マイクロアーキテクチャ が必要となります。

  • Intel ベースのシステムを利用する場合、Haswell 以上が必要となります。
  • AMD ベースのシステムを利用する場合、Excavator 以上が必要となります。Piledriver および Steamroller はサポートされません。

お使いの CPU がサポート対象かどうか確認するには、2023年の記事 CPU のマクロアーキテクチャファミリと命令セットの判定方法 をご参照ください。

 

Red Hat Enterprise Linux

  • 今後予定されている変更点
    • RHEL 10 - Red Hat が RHEL 10 を5月20日にリリースしました。 InterSystems は 6月20日に RHEL 10 をサポートする IRIS 2025.1.0 をリリースしました。
      • IRIS 2025.2 以降は、RHEL 9 および 10 をサポートします。RHEL 8 のサポートは終了しました。
  • Red Hat のリリースライフサイクルについては こちら をご覧ください

 

Ubuntu

  • 最近の変更点
    • Ubuntu 24.04.2 がリリースされ、マイナー OS 認証も問題なく完了しました。
  • Ubuntu のリリース履歴については こちら をご覧ください。

 

SUSE Linux

  • 今後予定されている変更点
    • IRIS 2025.3 以降では、SUSE Linux Enterprise Server 15 SP6 以上が必要となります。 SLES 15 sp6 では、OpenSSL 3 を使用するオプションが追加されています。お客様に可能な限り安全なプラットフォームを提供するために、OpenSSL 3 を使えるよう IRIS 内部処理を変更する予定です。
    • IRIS 2025.3 で OpenSSL 3 に移行する準備として、IRIS 2025.2 for SUSE はリリースされませんでした。
  • SUSE ライフサイクルについては こちら をご覧ください。

 

Oracle Linux

  • 今後予定されている変更点
    • Oracle Linux 10 のテストを開始しました。これまでの経験から、RHEL 10 をサポートする IRIS バージョンであれば問題なく動作すると考えています。
  • Oracle Linux のサポートポリシーについては こちら をご覧ください

 

Microsoft Windows

  • 過去にお知らせ済みの変更点
    • IRIS 2025.1 以降で Windows Server 2025 がサポートされています。
  • 今後予定されている変更点
    • IRIS 2025.3 以降は、Windows Server 2016 と 2019 はサポートされません。
    • Microsoft は、Windows 12 のリリース予定を再度延期しました。 この時点でリリース予定を推測することは難しいです。 リリースされ次第、新OSのサポートに向けて動く予定です。
  • Microsoft のライフサイクルについては、こちら をご覧ください。

 

AIX

  • 今後予定されている変更点
    • IBM は新しい Power 11 を7月にリリースしました。 夏の終わりから秋の初めにかけて、この新しいハードウェアをテスト予定です。 2025年第4四半期 もしくは 2026年第1四半期のニュースで、テスト結果のアップデートをお伝えする予定です
  • AIX のライフサイクルについては、こちら をご覧ください

 

コンテナ

  • 過去にお知らせ済みの変更点
    • IRIS 2024.2 で、ベース コンテナ イメージを Ubuntu 22.04 から Ubuntu 24.04 に変更しました。
    • 現在、ベース IRIS コンテナに変更を行い、デフォルトでは、( ECP やミラーリングなどの) 内部トラフィックと、( ODBC や JDBC などの) 外部トラフィックとを、別のポートにすることを検討しています。こちらに関してご要望がございましたら、@Bob Kuszewski までご連絡ください。

 

InterSystems IRIS 開発環境用オペレーティングシステムと CPU アーキテクチャ

MacOS

  • 最近の変更点
    • IRIS 2025.1 で、ARM ベース および Intel ベース の MacOS 15 のサポートを追加しました。

 

InterSystems コンポーネント

  • 今後予定されているリリース
    • InterSystems API Manager 3.10 がリリースされました。以前のバージョンの API Manager をご利用されている場合、新しい IRIS ライセンスキーが必要となります。
    • InterSystems Kubernetes Operator 3.8 がリリースされました。

 

Caché ならびに Ensemble 本番環境用オペレーティングシステムと CPU アーキテクチャ

  • 過去にお知らせ済みの変更点
    • Caché ならびにEnsemble の最終メンテナンスリリースは 2027年第一四半期に予定されていること、あらためてご留意ください。想像より早くその日はやってきます。詳細は Jeff の記事 をご覧ください。

 

InterSystems サポートプラットフォームに関するドキュメント

サポート・プラットフォームに関する以下のドキュメントにて、正式なサポートリストを入手いただけます。

 

以上になります。もし追加で知りたい情報がございましたら、ぜひコメントなどを通じてお知らせください。

Discussão (0)0
Entre ou crie uma conta para continuar
InterSystems Oficial
· Ago. 15

InterSystems Platforms Update Q3-2025

Welcome to the 2025 third quarter update.

Last quarter, we had a few important announcements that are worth reiterating this quarter.

  • RHEL 10 support was added to IRIS 2025.1
  • 2025.3 will use OpenSSL 3 across all operating systems SUSE 15 sp6 will be the minimum OS for orgs using SUSE
  • The minimum CPU standards are going up in 2025.3
  • Older Windows Server operating systems will no longer be supported in 2025.3

If you’re new to these updates, welcome!  This update aims to share recent changes as well as our best current knowledge on upcoming changes, but predicting the future is tricky business and this shouldn’t be considered a committed roadmap. 

InterSystems IRIS Production Operating Systems and CPU Architectures

Minimum Supported CPU Architecture

In 2024, InterSystems introduced a minimum supported CPU architecture for all Intel- & AMD-based servers that allows us to take advantage of new CPU instructions to create faster versions of IRIS.  IRIS 2025.3 will update that list to require the x86-64-v3 microarchitecture level, which requires the AVX, AVX2, BMI, and BMI2 instructions.

  • For users with Intel-based systems, this means that Haswell and up will be required.
  • For users with AMD-based systems, this means that Excavator and up will be required while Piledriver & Steamroller will not be supported.

Are you wondering if your CPU will still be supported?  We published a handy article on how to look up your CPU’s microarchitecture in 2023.

 

Red Hat Enterprise Linux

  • Upcoming Changes
    • RHEL 10 - Red Hat released RHEL 10 on May 20th.  We released a version of IRIS 2025.1.0 that supports RHEL 10 on June 20th.
      • IRIS 2025.2 and up will support RHEL 9 & 10, which means that we stopped supporting RHEL 8.
  • Further reading: RHEL Release Page

Ubuntu

  • Current Update
    • Ubuntu 24.04.2 has just been released and minor OS certification has completed successfully.
  • Further Reading: Ubuntu Releases Page

 

SUSE Linux

  • Upcoming Changes
    • IRIS 2025.3+ will require SUSE Linux Enterprise Server 15 SP6 or greater – SLES 15 sp6 has given us the option to use OpenSSL 3 and, to provide you with the most secure platform possible, we’re going to change IRIS to start taking advantage of it.
    • In preparation for moving to OpenSSL 3 in IRIS 2025.3, there was no IRIS 2025.2 for SUSE.

Further Reading: SUSE lifecycle

 

Oracle Linux

  • Upcoming Changes
    • We’ve started testing Oracle Linux 10.  If history is to be our guide, it should work just fine with any version of IRIS that supports RHEL 10.
  • Further Reading: Oracle Linux Support Policy

 

Microsoft Windows

  • Previous Updates
    • Windows Server 2025 is now supported in IRIS 2025.1 and up.
  • Upcoming Changes
    • IRIS 2025.3+ will no longer support Windows Server 2016 & 2019.
    • Microsoft has pushed back the anticipated release date for Windows 12 yet again.  At this point, it’s best to stop speculating on when it’ll arrive.  Whenever it does arrive, we’ll start the process of supporting the new OS then.
  • Further Reading: Microsoft Lifecycle

 

AIX

  • Upcoming Changes
    • IBM released new Power 11 hardware in July.  We anticipate running the new hardware through the paces over the course of the late summer and early fall.  Look for a full update on our findings in the Q4’25 or Q1’26 newsletter.
  • Further Reading: AIX Lifecycle

 

Containers

  • Previous Updates
    • We changed the container base image from Ubuntu 22.04 to Ubuntu 24.04 with IRIS 2024.2
    • We’re considering changes to the default IRIS container to, by default, have internal traffic (ECP, Mirroring, etc) on a different port from potentially externally facing traffic (ODBC, JDBC, etc).  If you have needs in this area, please reach out and let me know.

 

InterSystems IRIS Development Operating Systems and CPU Architectures

MacOS

  • Recent Changes
    • IRIS 2025.1 adds support for MacOS 15 on both ARM- and Intel-based systems.

 

InterSystems Components

  • Upcoming Releases
    • InterSystems API Manager 3.10 has been released.  Users of earlier versions of the API manager will need an updated IRIS license key to use version 3.10.
    • InterSystems Kubernetes Operator 3.8 has been released.

Caché & Ensemble Production Operating Systems and CPU Architectures

  • Previous Updates
    • A reminder that the final Caché & Ensemble maintenance releases are scheduled for Q1-2027, which is coming up sooner than you think.  See  Jeff’s excellent community article for more info.

InterSystems Supported Platforms Documentation

The InterSystems Supported Platforms documentation is the definitive source information on supported technologies.

 

… and that’s all folks.  Again, if there’s something more that you’d like to know about, please let us know.

2 Comments
Discussão (2)1
Entre ou crie uma conta para continuar
Artigo
· Ago. 15 8min de leitura

Beginner's Guide to %JSON and Dynamic Entities in IRIS

Dynamic Entities (objects and arrays) in IRIS are incredibly useful in situations where you are having to transform JSON data into an Object Model for storage to the database, such as in REST API endpoints hosted within IRIS. This is because these dynamic objects and arrays can easily serve as a point of conversion from one data structure to the other.

Dynamic Objects

Dynamic Objects are very similar to the standard ObjectScript object model you get when you create a new instance of a class object, but with some key differences:

  • Dynamic objects have no real type, other than being a DynamicObject or DynamicArray
  • They cannot inherit or be morphed directly into a class object
  • They're much easier to create and come with a host of built-in functions for managing and manipulating them

To create a dynamic object, it's as easy as:

set obj = {}

We now have "obj" as a dynamic object. If you've used Javascript/Typescript before, this will look very similar. This connection to Javascript becomes very important when talking about arrays later.

With our new dynamic object, we can add and manipulate properties of this object just like we can with class objects, which the added flexibility of not having to predefine properties that the object can use.

set obj.message = "This is a test message"
set obj.num = 4
set obj.test = 1

So far, this all looks similar to the standard ObjectScript model. Here's where things get interesting:

set obj.subobj = {}

Now, we've created a completely new dynamic object within our existing dynamic object, with all the same functionality as the existing one.

set obj.subobj.message = "This is a message on the sub-object."

As you can see, we can string the dot notation together to access properties of sub-objects on a dynamic object. We can also assign dynamic objects as sub-objects on an existing object:

set obj1 = {}
set obj1.message = "This is object 1"
set obj2 = {}
set obj2.message = "This is a different object, object 2"
// Set the "subobj" property of obj1 to the entire obj2 object
set obj1.subobj = obj2

// Set the "obj1" on the original "obj" object to the entire "obj1" object, which
// also now includes "obj2"
set obj.obj1 = obj1

You can also use the %Set(), %Get(), and %Remove() methods on the object (and arrays) to manipulate the data stored in object properties, which is especially useful for properties that have long names. %Remove() is the only real way to remove a property or element from a dynamic object or array.

Dynamic Arrays

We've talked about dynamic objects a lot up to this point, but what about dynamic arrays?

These work very similarly to the objects. To create one:

set array = [1,2,"three",true]

Notice that rather than creating the empty array first and then adding items to it, I've given it a starting value. This can also be done with objects:

set test = {"message":"Test message","num":4}

Also notice that when defining objects this way, the property names must be quoted or else you will get a syntax error.

NOTE: It is CRITICAL to understand that dynamic arrays will be 0-indexed, as opposed to standard IRIS arrays which are 1-indexed. All dynamic arrays start at index 0.

Getting back to arrays, once you have your array you have access to some standard methods for interacting with it, such as:

  • %Push(element) - Add a new element to the end of the existing array
  • %Pop() - Remove and return the last element in the array
  • %Size() - Get the number of elements currently in the array
  • %IsDefined(element number) - Returns whether or not the given key (array index number) exists in the array.

 

Combining Objects and Arrays

As is standard in JSON, you can have an object with properties containing arrays and arrays that contain a set of objects. As shown above when setting sub-objects onto other objects, you can do the same for dynamic arrays as well.

Adding an array to an object:

set obj = {"message":"This is a message"}
set array = [1,2,3,4,5]

set obj.array = array

Adding an object to an array:

set newobj = {"message1":"Message 1", "message2":"Message 2"}
set newarray = [1,2,3]
do newarray.%Push(newobj)

 

JSON Conversion and Formatting

More than likely, in a real setting these entities are likely to be quite large and difficult to mentally keep track of what properties are where, and what is in an array.

For instance, let's say we have this code:

set testObj = {}
set testObj.message = "This is a test message"
set testObj.num = 4
set subobj = {}
set subobj.message = "This is a message on the sub-object."
set testObj.subobj = subobj

set array = [1,2,3,4,5]
set newobj = {"six":6}
do array.%Push(newobj)

set testObj.array = array

There is a lot going on here with a mix of arrays and objects that make it difficult to mentally map out. To help with this, we can make use of the built in %ToJSON() method which will convert the object into a properly formatted JSON string:

write testObj.%ToJSON()

Which will produce this output:

{"message":"This is a test message","num":4,"subobj":{"message":"This is a message on the sub-object."},"array":[1,2,3,4,5,{"six":6}]}

This is a good start, but it's not very readable. Let's have a look at the %JSON.Formatter class, which has a Format method. To use this, we can create a new instance of %JSON.Formatter, and then call the Format method which takes the JSON string as an input.

set formatter = ##class(%JSON.Formatter).%New()
do formatter.Format(testObj.%ToJSON())

Which gives us a nicely expanded, properly formatted JSON object display:

{
  "message":"This is a test message",
  "num":4,
  "subobj":{
    "message":"This is a message on the sub-object."
  },
  "array":[
    1,
    2,
    3,
    4,
    5,
    {
      "six":6
    }
  ]
}

 

 

Working with True/False in Dynamic Objects

Standard IRIS does not understand the keywords "true" or "false" typically. To represent these values in IRIS ObjectScript, we must use 1 or 0. 

However, when working with dynamic entities, you begin crossing more into Javascript territory which uses "true" and "false" just fine, but there are some limitations.

When defining an object or array, if you're working with a value or set of values contained within the [ ] or { }, then you can set properties or elements as "true" or "false" with no problem. These values will be represented as the Javascript representation of true and false when defined in this way. Outside of that context, IRIS will convert these values to 1 or 0 when displaying them in an ObjectScript context.

If, however, you're using dot syntax to manually set a property on an object, you can only use the IRIS syntax of 1 or 0, otherwise IRIS will throw a syntax error.This has the unfortunate side effect that the Javascript representation sees 1 and 0 as valid values, but with a very different meaning than what may be intended.

To work around this, you can use the %Set(key, default, type) method which takes the key you want to set (object property or array element), an optional default value, and then a string type value, which can be "null", "string", "number", or most importantly, "boolean". When using the %Set() method with a type of "boolean", the 1 and 0 values are then converted to the Javascript representation of "true" and "false". The %Push() method on dynamic arrays can also take a type parameter in the same way. Arrays also have the %Set() method to set a value of a given array index.

See the documentation on %Set() and %Push() for details.

 

Converting a JSON string into a dynamic object or array

So, this is all great when we want to create a JSON object to perhaps send as a response to a REST API request. Simply setup a dynamic object with all the appropriate properties, and write it out and the downstream system will see it as a proper JSON object.

But, what about that initial request that has a POST body in JSON format? How can that be converted from the JSON string into a dynamic object or array?

Similar to the %ToJSON() method we used earlier, there is also a %FromJSON() method which takes the JSON string as the parameter and sets up the object/array according to the JSON definition.

For example, if we use the same JSON string we got earlier:

set jsonString = {"message":"This is a test message","num":4,"subobj":{"message":"This is a message on the sub-object."},"array":[1,2,3,4,5,{"six":6}]}

We can convert this into an object like this:

set obj = {}.%FromJSON(jsonString)

This will set the "obj" variable to be the dynamic object representation of the given JSON.

Now, let's say we have an array of books that we need to process:

[
	{
		"id": 1,
		"title": "ObjectScript for Dummies",
		"type": "paperback"
	},
	{
		"id": 2,
		"title": "Intermediate ObjectScript",
		"type": "paperback",
	},
	{
		"id": 3,
		"title": "Advanced ObjectScript",
		"type": "hardback",
	},
	{
		"id": 4,
		"title": "IRIS Embedded Python and You",
		"type": "paperback",
	},
]

 Since we're getting this data from another system, we have no way of knowing how many elements will be in this list when we get it. Thankfully, both dynamic arrays and objects are iterable! 

We can use the %GetIterator() method coupled with the %GetNext(.key,.value) method to iterate through each object in the array, or each top-level property of an object, to access the individual data.

set booksJSON = set booksJSON = "[{""id"": 1,""title"": ""ObjectScript for Dummies"",""type"": ""paperback""},{""id"": 2,""title"": ""Intermediate ObjectScript"",""type"": ""paperback""},{""id"": 3,""title"": ""Advanced ObjectScript"",""type"": ""hardback""},{""id"": 4,""title"": ""IRIS Embedded Python and You"",""type"": ""paperback""}]"
set booksArray = [].%FromJSON(booksJSON)

set bookIter = booksArray.%GetIterator()

while bookIter.%GetNext(.key,.value) {
    write !,"Book ",value.id,": ",value.title," (",value.type,")"
}

Which presents our request payload in a nice display list:

Book 1: ObjectScript for Dummies (paperback)
Book 2: Intermediate ObjectScript (paperback)
Book 3: Advanced ObjectScript (hardback)
Book 4: IRIS Embedded Python and You (paperback)

 

Documentation

For more information about how these entities can be used, please read the IRIS guides and class documentation:

Creating and Modifying Dynamic Entities
%Library.DynamicObject
%Library.DynamicArray

1 Comment
Discussão (1)2
Entre ou crie uma conta para continuar
Pergunta
· Ago. 15

Removal of Provider.Individual.Addresses from Local.PD.DataGram.Main.Unified using %clearFields

Is there a way to Remove specific all Addresses from a Provider.Individual.Address before reinserting the Addresses from an HL7 message in Provider Directory?

Most fields we can call %clearFields() however since Addresses come from multiple locations we need to isolate and treat Addresses from this HL7 source as a snapshot.

Thanks

Scott

Discussão (0)1
Entre ou crie uma conta para continuar