#ObjectScript

14 Followers · 1.6K Posts

InterSystems ObjectScript is a scripting language to operate with data using any data model of InterSystems Data Platform (Objects, Relational, Key-Value, Document, Globals) and to develop business logic for serverside applications on InterSystems Data Platform.

Documentation.

Question alex chang · Sep 14, 2020

I want to call some Java Remote Call through Java gateway.  The call code as following:

class CallRemote Extends %CSP.REST {

Method Index() as %Status {

Try

      set gw = createJavaGateway()

     Do callJavaMethod(gw)

     do gw.%Disconnect()

Catch {

}

}

}

But Every call need connect to Java Gateway and disconnect it. But It's cost too high( about 80ms)

So, According to my Java experences, I need create some connection and put it into global static ConnectionPool

But I don't known how to reach that using ensemble.

2
0 268
Discussion Evgeny Shvarov · Sep 21, 2020

Hi Developers!

Recently we discussed the naming convention on packages we deploy and even made some choices.

Here I want to have a conversation on the naming convention for unit tests.

Of course, we wish every good library has unit tests. Here is the documentation and some good articles(one, two, three) regarding it on the Developer Community.

Let's decide on the naming of UnitTests packages?

The suggestion is that unit test classes will all start with the UnitTest package name.

E.g. if your library's class name is:

johndoe.lib.class

The related unit test class will be:

UnitTest.johndoe.lib.class

What about folders?

The suggestion is that unit test classes will live separately from source classes, e.g. in /tests directory.

Here is the example of a repository with unit tests that are named and placed according to the proposal.

What do you think?

6
0 453
Question ED Coder · Sep 17, 2020

My segment is not getting set with the new value though It goes into the if statement. Am I doing something wrong?

ClassMethod Clone(pRequest As EnsLib.HL7.Message) As EnsLib.HL7.Message [ Final ]

s cREQ = pRequest.%ConstructClone()

s DG1 = cREQ.FindSegment("DG1",.ind)

While (ind2 '="")

{
diag = DG1.GetValueAt(4.1)

if diag = "0"
{
tmp = "No code"
rc=DG1.SetValueAt(tmp,4.1)
}

}

DG1 = cREQ.FindSegment("DG1",.ind2)

request = cREQ
Quit request

}

6
0 478
Question Keith Davis · May 31, 2019

Forgive my lack of understanding, but I am working on a vendor created Cache database and the indexes specified in the classes for ODBC connections are not working. A few of them are created, but of the 50+ classes we have, only a handful of them are created when the class is compiled, yet no errors occur.

Example 1:

Example 2:

The code is creating the Index, and again, not compile errors, but most of the indices are not built.

21
0 1461
Question VICTOR GALVAO · Sep 15, 2020

Hi guys!!

In the system that I work, I came across an iterator pattern that uses the %Resultset library without performing the close after executing the query. Does anyone know how to say what are the impacts of not performing such a procedure?

If you have any model of iterator pattern made in caché to recommend as a good example, I will be grateful hehe  :D

5
0 404
Announcement Raj Singh · Sep 1, 2020

Hello Developer Community!

I’m pleased to announce the 0.9 release of the ObjectScript extension for Visual Studio Code. Earlier this year I announced that InterSystems would be joining the community in evolving this already popular tool. Since then, we have been hard at work solidifying the code base and building a slew of new features.

9
2 944
Question alex chang · Sep 13, 2020

Common macro def as following

#def AnyNumber(%args) for i=1:1:$listlength(%args) { Write $listget(%args, i)}

Using this marcro in objectscript code:

ClassMethod Test() as %Status {

     $$$AnyNumber($lb(1,2,3))

}

if ths args is literal value , Iit worked great. But  When I want pass Objects, It's not working

$$$AnyNumber($lb(##class(someClass).%New()))

I know I can pass a %ListObjects , If I want more shorter Line. How can I do this.

Tks

1
0 316
Question Scott Roth · Jun 19, 2017

I have come across several cases where I need to set a Date filter to send only send any admit/scheduled date past a certain point. We have a couple different date comparison functions but none looking at the true date. Most of them are date + 15 or etc. Does anyone have a good date function they have written to say if x > 20170102 ?

Thanks

Scott

14
0 2466
Question alex chang · Sep 3, 2020

I  have java  language experence. If I need parse a binary tcp packet . like following format

encoded string and send it to peer by tcp

1byte msg type + 4 byte(unsigned int) + raw byte(body)

To parse this package , Some Java code like this:

byte[] data = new byte[1024];

Bytebuf buf  = new ByteBuf(data)

byte type = buf.read()

int len = buf.ReadInt()

byte[] bodyBuff = new byte[len]

buf.Read(bodyBuff)

String str = new String(strBody)

So, does Objectscript have similar functionality to achieve similar results?

Tks.

1
0 419
Article Daniel Tamajon · Sep 1, 2020 5m read

Error management on InterSystems languages has been evolving along time. Next, we will show the different implementations and why you should use the TRY/THROW/CATCH mechanism.

You can read official error recommendations here.

InterSystems will not mark as obsoletes the non-recommended error management methods to allow giving support to legacy applications. We recommend using tools like objectscriptQuality to detect that legacy unrecommended usage along with many other possible issues and bugs.

$ZERROR

2
3 992
Question Oliver Wilms · Aug 19, 2020

I was able to define ECP connection in Installer class that I run when I build docker image for my Docker IRIS application. Now I start to use Amazon ECS and Autoscaling. When a new instance is created and it runs the IRIS container, I want it to "register" as an Application server on the remote database server. What code can I execute to add an ip address as an Application Server?

2
0 553
Question ED Coder · Aug 27, 2020

I have a list of 300 code combinations in the following format, which I plan to load into a global

X123, Internal health

X234, external health

X345, Peripheral health etc..

I want to get the code from the DG1 segment, compare to the global, and add a description. Is there an easy way to do it?

So in my DG1 segment If I get the code X123, what I want to do is check if the code is in the global and if it does add the description in the field.

So DG1 will look like this:

DG1|1|CDS||X123^^^|20200827141200|Primary||||||||||Dr. Who|||

and needs to be transformed as below

7
0 296
Question Ba Moser · Aug 25, 2020

I use these example classes:
Class Sample.Address Extends (%SerialObject, %Populate)
{Property Street As %String;
Property City As %String;
Property State As %String(POPSPEC = "USState()");
Property Zip As %String;}
Class Sample.Person1 Extends (%Persistent%Populate)
{  Property Name As %String;
Property Home As Sample.Address;
Property AR As array Of Sample.Address; }

In SQL it is Table Sample.Person1

No problem to define INDEX on Home_State

But Table Sample.Person1_AR

HowTo define an INDEX on AR_State ?
Index st On AR.State;

Does not compile!

12
0 750
Question Daniel Lee · Aug 20, 2020

We are using Ensemble and I added some debug logging that writes to a global and recompiled the class in Studio. However, when we send messages, the global is not populated. I have recompiled, removing the checkmark to keep the generated code so that there is only one .INT file and I verified that the code is present in the .INT file. 

My question is, do we need to stop and restart the Ensemble production in order for these changes to take effect? Do I need to stop and restart the business operation that calls this piece of code? Is there something else I may have missed?

6
0 413
Question Jude Mukkadayil · Aug 12, 2020

Hi,

     Can anyone please explain me how to remove trailing squares from the text field (String). Trailing squares is a white space ?

I tried different things like Ltrim, Trim from sql query side and also from object scripting side something below.

 If Address1 set Address1 = $ZSTRIP(Address1,"<>P,<>C,<>W")
 If Address1 set Address1 = $ZSTRIP(Address1,"$C(9), $C(32), $C(160)")
 If Address1 set Address1 = $ZSTRIP(Address1,"*W,*C")

Nothing works for me

Can anyone please help me to solve this

Thanks

5
0 907
Question Scott Roth · Aug 12, 2020

We have a vendor that every couple of days will just stop transmitting messages, but still hold the TCP/IP connection open. No matter how many times we troubleshoot and talk with them, they don't seem to think its an issue with system.  Normally if I just restart the service it will get the data flowing again.

I know ideal is for them to fix the issue, but in the meantime I have setup an Inactivity time out alert.  I was wondering with the correct filtering if there was a way to say if the Inactivity Alert is triggered during the business day, to have the Alert trigger a restart of the service?

3
0 326
Article Evgeny Shvarov · Aug 2, 2020 1m read

Hi Developers!

As you know the application errors live in ^ERRORS global. They appear there if you call:

d e.Log() 

in a Catch section of Try-Catch.

With @Robert Cemper's approach, you can now use SQL to examine it.

Inspired by Robert's module I introduced a simple IRIS Analytics module which shows these errors in a dashboard:

5
1 405
Question sjbttt sjbttt · Apr 8, 2020

Now I want to return a large amount of data to the front end. The string length has reached 40000 +, and the returned data needs to be encrypted by AES + Base64. I can convert the string into a stream. AES can use the AESCBCEncryptStream method to encrypt, but Base64 has no stream method。Anyone who get the solution  would you kindly share the solution please。

Any help would be appreciated. Thanks!

10
0 15182
Discussion Evgeny Shvarov · Jun 11, 2020

Hi Devs!

A few months ago I raised a discussion on the naming convention for ZPM modules.

And you free to put your name or your organization name for the packages you want to have your personal or company's brand.

But if you contribute to community, we suggested to have "community." package for all such libraries.

But the name is too long.

What if we use "isc." instead?  Which can be read as "isc ->InterSystemsCommunity". Short and unique.

What do you think?

 
19
1 630
Article Robert Cemper · Jul 27, 2020 2m read

The offer of ZPM is growing daily and the short names and
acronyms of the offer are sometimes hard to understand and
also hard to type with my lazy fingers.

So I decided to have

  • a listing with the descriptions from the repository,
  • split in short junks to avoid backscroll,
  • controlled forward / backward scrolling,
  • the option to select my packages by number,
  • to install or uninstall with limited typing.

It runs with do ^zpmshow

A snapshot from the screen:

USER>d ^zpmshow
0
0 463
Question Yone Moreno · Jul 21, 2020

It would be interesting if there is some recommended documentation about best practices using Healthshare for interoperability.

Also, some how-tos or frequently asked questions about ObjectScript.

Or event better, if there are experienced developers who would like to share some common habits on their work with Studio / ObjectScript, which are valuable to do the developing work better.

For example, How to get the XML of a class and write it into a REST operation:

...

Method X(pRequest As Mensajes.ServiciosGeneralRequest, ...){

1
0 268
Article Robert Cemper · Jul 21, 2020 1m read

This is a sample to use %JSON.Adaptor class available in IRIS to produce a snapshot of your object.

The sample consists of 2 classes that are variations of what was known in Caché/SAMPLES as Sample.Person.
Be aware that the possibilities are limited by %JSON.Adapter and how you make use of it.

Once in place, you create some test data by Populate().
You select an object and take a snapshot.
You apply changes to your object and take another snapshot.
And see the difference.

BINGO!

GitHub

0
0 775