Find

Announcement
· Mar 5, 2021

How to Become a Helpful Member of Developer Community

Hi Developers!

Recently we are getting a lot of requests on how to become an active and helpful member of the InterSystems Developer Community.

The terms are very simple:

1. Answer questions

we have a lot of unanswered questions, and questions without an accepted answer. You are very welcome to share your knowledge and help other members of the community.

2. Contribute articles

Write articles that describe your experience with InterSystems technology: your solution, your know-how on development, tips and tricks on debugging, deployment, and other approaches in robust development.

There are a lot of examples of articles that became very helpful to the community.

Or translate articles to other languages on regional communities.

3. Contribute Open Exchange applications

Share your libraries, solutions, and tools on Open Exchange - via Github, Gitlab, or any other public repositories.

Please don't hesitate to ask your questions in this post and let's discuss how to make this community more and more helpful for engineers working with InterSystems technology all over the world.

17 Comments
Discussion (17)11
Log in or sign up to continue
Question
· Mar 3, 2021

How to update Ensemble - Business Hosts settings (default and custom settings) through code ?

Hi ,

I have a requirement to programmatically fetch and update a Business Process Setting . It's a custom property , added in extended class .

I am trying find a sample, but no luck. 

Could any one help me ? 

3 Comments
Discussion (3)0
Log in or sign up to continue
Discussion (1)0
Log in or sign up to continue
Article
· Feb 18, 2021 3m read

jQueryを使用してIRISからJSONデータを取得する方法

jQuery($.getJSON と $.ajax)を使用した InterSystems IRIS データのJSON形式での取得方法をご紹介します。

以下にサンプルをご用意しました。

https://github.com/Intersystems-jp/REST_JSON_sample


サンプルには、次の内容が含まれます。

・REST + JSON
・REST + CORS

※それぞれ、$.getJSON と $.ajax で取得する方法を記載しています。

※サーバ側ではSelect文の実行結果をJSON_OBJECT関数を使用しJSON文字列で出力しています。
 関数については以下のドキュメントをご覧ください。
 JSON_OBJECT関数


使用手順は以下になります。

1. USERネームスペースに json.xml をインポート・コンパイル
 

2. テスト用データの作成(ターミナルで以下のコマンドを実行する)

    USER>do ##class(Sample.Person).Populate(200)


3. 初期設定(REST用)

   管理ポータル > セキュリティ管理 > ウェブ・アプリケーション

   新しいウェブ・アプリケーションを作成ボタンを押す

   名前 /csp/user/rest
   ネームスペース    USER
   ディスパッチ・クラス REST.Person

   保存ボタンを押す

4. test_json.html をWEBサーバに配置する

   例:
   C:\Inetpub\wwwroot                          <-- IIS ルート
   C:\InterSystems\IRIS\CSP\user       <-- cspフォルダ

5. test_json.htmlをブラウザで開く

   例:
   http://localhost/test_json.html
   http://localhost:52773/csp/user/test_json.html
    
    ※サンプル内のクロスドメイン対応URLは、http://127.0.0.1:52773/ を使用(PWS用サンプル)
 

6. テキストボックスに適当なID(1,2,100 など)を入力し、検索ボタンを押して出力結果を確認する。

 

★IRISでJSONを操作する基本情報については、こちらの記事をご覧ください(ビデオもご紹介しています)。

【はじめてのInterSystems IRIS】セルフラーニングビデオ:アクセス編:IRIS での JSON の操作

 


【注意】

IRIS 2025.1以降のバージョンでGitHubのサンプル(REST+CORS)を実行すると、以下のような CORS エラーになります(F12/開発者ツールで確認)。

Access to XMLHttpRequest at 'http://127.0.0.1/csp/user/rest/persons/2' from origin 'http://<IP Address>' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.


これは、2025.1 以降のバージョンより、管理ポータルの Web アプリケーション設定 で受け入れるオリジンを制限することができるようになったことが関係しています。

管理ポータルの、[システム管理] > [セキュリティ] > [アプリケーション] > [ウェブ・アプリケーション] RESTアプリケーション(例:/csp/user/rest)より、
[Cross-Origin 設定] タブで、許可されるオリジンまたはヘッダを追加します。オリジンまたはヘッダを追加するには、対応するボックスに名前を入力して [新しく追加] をクリックします。

ワイルドカードのアスタリスク (*) を入力して、すべてのオリジンを許可することもできますが、この場合は、CORS ヘッダを処理する方法を定義する必要があります。
 

   

Discussion (0)0
Log in or sign up to continue
Article
· Feb 16, 2021 2m read

FOREACH for Objectscript

As you know ObjectScript has neither FOREACH system command nor system function.
But it has a wide room for creativity.

The task is to loop over a global or local array and do something FOR EACH element.

There are 2 possible solutions:

  • creating a macro that generates the required code sequences
  • creating an Extended Command to perform the action. Both ways are presented here. The macro is a generic and quite flexible solution and easy to adapt if required.
##; ZFOREACHMACRO ; macro definitions
##; %key = variable provide to loop trough array
##; %arr = the gobal or local array to be looped on
##; %the method or routine to be executed for each node.
##; $$$foreach = forward loop $$$foreeachR = reverse loop
#define foreach(%key,%arr,%do) set %key="" for  set %key=$o(%arr(%key)) q:%key=""  do %do
#define foreachR(%key,%arr,%do) set %key="" for  set %key=$o(%arr(%key),-1) q:%key=""  do %do

You simply include the macro and apply it.
Example:

#include ZFOREACHMACRO   
test $$$foreach(key,^rcc,show)   
     quit
show zwrite @$zr,! quit   

Creating a command extension is available for all namespaces.

It needs to be included in %ZLANGC00.mac by #include ZZFOREACH
the related code is here:

##; run $order() ascending or descending on global or local arrays  
##; pass semicolon separated parameter string ("%array;%do;%fwd,;%key")  
##; %array = global or local variable name  
##; %do = routine or method to be executed for each run   
##; %fwd = 1/-1 loop direction ascending / descending, default = 1   
##; %key = first key if existing  
ZZFOREACH(%par) public {  
 set %par=$lfs(%par,";")
 new %array,%do,%fwd,%key,%val
 set %array=$lg(%par,1),%do=$lg(%par,2),%fwd=$lg(%par,3),%key=$lg(%par,4)
 if '%fwd set %fwd=1
 if %key]"" set %key=$o(@%array@(%key),$s(%fwd<1:-1,1:1))
 for  set %key=$o(@%array@(%key),%fwd,%val) quit:%key=""  do @%do
 quit 1 
}

In addition to the macro, the command allows optionally to run zzFOREACH
from a provided starting point forward or backward.
Examples:

DEMO>zzforeach "^rcc;show^dump(%array,%key,%val)"
^rcc(1) = 1
^rcc(2) = 2
^rcc(3) = 3
^rcc(4) = 4
^rcc(5) = 5

or from subscript 3:

DEMO>zzforeach "^rcc;show^dump(%array,%key,%val);;3"
^rcc(3) = 3
^rcc(4) = 4
^rcc(5) = 5

or the same reverse:

DEMO>zzforeach "^rcc;show^dump(%array,%key,%val);-1;3"
^rcc(3) = 3
^rcc(2) = 2
^rcc(1) = 1

GitHub

1 Comment
Discussion (1)2
Log in or sign up to continue