#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 Christine Hall · Oct 23, 2023

I am making a POST request to an API. In the case of an error, I don't know what parameters the response JSON will contain (they will change depending on the error). I am converting the response stream to an object but then I need a way to loop through all the properties and access their values. The following code is making the POST request, reading the response, and trying to add all the error messages to an array. But I can't iterate over the properties of the tProxy.errors object because it is a %ZEN.proxyObject. Is there a better way to do this?

2
0 321
Article Mihoko Iijima · Oct 12, 2023 1m read

InterSystems FAQ rubric

ObjectScript allows you to pass any number of arguments using arrays. Do it by adding ... after the argument name.

An example is as follows. In the example statement, the argument information is set in a global variable (a variable stored in the database) so that it can be easily checked after the method is executed.

Class TEST.ARGTEST1 Extends%RegisteredObject
{
ClassMethod NewMethod1(Arg... As %StringAs %Boolean
{
 kill ^a
 merge ^a = Arg
}
}

The result of running it in the terminal is as follows.

1
0 520
Question Emil Odobasic · Oct 10, 2023

Hello everyone!
I have manually created a REST-service that receives incoming HTTP-GET calls together with an URL-map. As shown below:

XData UrlMap [ XMLNamespace = "https://www.intersystems.com/urlmap]
{
<Routes>
<Route Url="/testGet" Method="GET" Call="Handler" />
</Routes>
}

ClassMethod Handler(req As %Stream.Object) As %Status
{
set Class = ##class(Ens.Request).%New()

set status = ##class(Ens.Director).CreateBusinessService("TestService", .instance)
set status = instance.OnProcessInput(Class, .response)

if $ISOBJECT(response)
{
         write response.%ToJSON()
}Quit $$$OK
}

6
0 486
Question Timothy Leavitt · Sep 12, 2023

It's a feature of ObjectScript (perhaps widely known, perhaps not) that if you open the same object ID multiple times, you end up with the same OREF. For example:

USER>set obj1 = ##class(Sample.Person).%OpenId(1)
 
USER>set obj2 = ##class(Sample.Person).%OpenId(1)

USER>w obj1,!,obj2
1@Sample.Person
1@Sample.Person

Generally speaking, this is an important feature - you won't end up accidentally modifying the same record via multiple paths and losing some of the changes.

10
2 508
Question Evan Gabhart · Oct 5, 2023

I am currently debugging a piece of code relying heavily on macros. I am using breaks in the method to then check the values of macros and object properties as I go. However, any time I invoke a macro within a break I get an error. To get around this I am converting the macro calls into the underlying code. Some of these macros have messy translations and this is somewhat time consuming. Is there an easier way to access macros from within a break?

5
0 305
Article Megumi Kakechi · Sep 28, 2023 2m read

InterSystems FAQ rubric

In the sample below, an image file is encoded into a Base64 string in a class property, saved, decoded again with Base64, and restored to another file.

【Usage class】

Class User.test Extends %Persistent
{
Property pics As %GlobalBinaryStream;
}


【When importing】

2
2 724
Question Jan Cermak · Sep 27, 2023

Hi All,

is there any way how to hide or remove storage "Histogram" section in the file with persistent class definition, but keep the data both in globals and sql table?
The reason is that we use on-premise version control system and since the data is sensitive, it cannot be uploaded along with the files.

I have already tried "NoExtent" keyword, but that does remove the sql table and just keeps the data only in globals. The only solution I have come up with so far is to remove all the "property" sections from storage in file everytime before committing changes.

2
0 343
Article Robert Cemper · Sep 26, 2023 1m read

The related package avoids adding %JSONAdaptor to each class but uses  instead   
SQL functions JSON_OBJECT() to create my JSON objects. With this approach, you can   
add JSON to any class - even deployed ones - without any need for change or recompiling.

The trigger was the Export of M:N relationships  as JSON  objects or arrays.

0
0 453
Question Pietro Di Leo · Sep 22, 2023

Hi everyone,

Today I have a simple yet potentially valuable question: How can I begin a new line of text within $$$LOGINFO or $$$TRACE?

For instance, if I need to display a long log message within the visual trace, is it possible to do something like this:

$$$LOGINFO("object: 'This is a try'"
    _"this is the second line with an example parameter: "_x
    _"this is the third line with an example parameter: "_y
    ")

Does anyone know if such a feature exists? It has the potential to greatly enhance code readability and layout. 

Thanks :) 

6
0 1186
Question Ryan Pflughaupt · Sep 21, 2023

Currently I have a program that is going to be used to compare global nodes between namespaces. Using nested FOR statements I am stepping through global nodes and comparing between the namespaces, if the global values are different I then parse the node comparing each delimited segment.

This is working.

I want to now be able to set what global I am in as a variable to expand on this concept. 

Program architecture

3
0 444
Article Sylvain Guilbaud · Sep 18, 2023 6m read

Hello developers,

In this article, I'll show you how to run code at compile time with ObjectScript macros.

Here's a use case that recently led me to use this feature:

As part of a medical application developed for more than 20 years, we have a large number of parameters. Although we have procedures for documenting these settings, it can be helpful to have a quick view of which settings are actually used by the application code.

0
1 462
Question Ted Guarriello · Aug 17, 2023

Is it possible to "Ping" a remote host in IRIS for Health using ObjectScript? We host hundreds of TCP connections over hundreds of VPNs. I'm working on a project that would make it nice to have way to ping remove clients over the VPN to monitor connectivity and keep the tunnels alive.  

Another thought/method would be to make an OS system call (AWS Linux), but I don't see a way to do that either.

9
1 520
Question Cedric Montanuy · Sep 1, 2023

Hello, 
as i'm trying to develop a operation and its methods (SQL adapter), I'm running into issues when i run my test class. 
I have the class i want to test in the very same folder as my test class. 
I followed the tutorial in the documentation. 
When i run the test class, i get the following message error : 
LogStateStatus:0::ERREUR #5002: Erreur Cache: <METHOD DOES NOT EXIST>zTestAdd+1^unitTests.testMyClass.1 *myMethod,Package.BO.MyClass  
Here is my test class (heavily inspired bythe documentation :-) :
 

Class unitTests.testSqlInscription Extends %UnitTest.TestCase

3
0 447
Article Mihoko Iijima · Sep 7, 2023 1m read

InterSystems FAQ rubric

You can avoid the error by specifying a stream object as the argument of %ToJSON() used when generating a JSON string from a dynamic object.

A code example is below.

USER>set temp=##class(%Stream.TmpCharacter).%New()

USER>set jsonobj={}

USER>set jsonobj.pro1=["a","b","c","d"]

USER>set jsonobj.pro2=["あ","い","う","え"]

USER>do jsonobj.%ToJSON(temp)

USER>write temp.Size
51
USER>write temp.Read()
{"pro1":["a","b","c","d"],"pro2":["あ","い","う","え"]}

See also the documentation for details.

[IRIS] Serializing large dynamic entities to streams

1
0 648
Question David Loveluck · Sep 6, 2023

on red hat, but I would also be interested in a wider answer.

after running a benchmark for 40 minutes, I have been asked if any rollbacks occurred in that time. Rollbacks from SQL or objects.

The application does not record this, so I am looking for a system level record.

The journal entries do the necessary reverse sets and commit just like any transaction. So i don't think i can detect them there.

4
1 546
Question Smythe Smythee · Aug 23, 2023

Hi Community ,

I am using %Date Property for defining one csv source message class .Please refer below class

Class CSVtoHL7.Inputfile.Record Extends ,(%XML.Adaptor, Ens.Request, EnsLib.RecordMap.Base) [ Inheritance = right, ProcedureBlock ]

{

Property ID As %Integer;

Property LastName As %String;

Property FirstName As %String;

Property MiddleName As %String;

Property DOB As %Date;

Property Gender As %String;
}

Please refer to data transformation class

14
0 740
Question Moritz Siegert · Aug 31, 2023

Hi there,

I want to use regex in my code, and I saw that the %Regex.Matcher class contains a property "OperationLimit" that you can also set to a number of steps that the regex engine should take maximum in analysing a given string. So far so good.

I tried to set the property with the function OperationLimitSet() to a silly value like 3. In 3 steps only very few regex should be executed, right? But what I found is that my regex always comes up with a solution. Here is what I did:

First I initialised my %Regex.Matcher.

1
0 218
Question John Maclain Wright · Aug 26, 2023

Hey, I'm working with HealthShare 2016.2 and trying to implement a custom integration using ObjectScript. I have followed the usual syntax for setting up the integration, but I keep getting an undefined variable' error. Has anyone encountered a similar issue? Here's a snippet of the code I'm using :
set customData = 'Sample Data';
write customData;
 

1
0 138
Question Scott Roth · Jul 8, 2019

Way back when during our Siemens LCR days we had to limit the number of characters in OBX.5 to a length of 75. That was back when we had eGate.

Now I need to do the reversal of that and take loop through a string length and split the string up into multiple OBX or NTE based on a certain length. In reading documentation $EXTRACT can do this if you know the exact length, but in this case we don't. 

So how would one loop through a string and say every 75 characters create a new OBX or NTE segment?

Thanks

Scott

7
0 3111
Announcement Ali Nasser · Aug 8, 2023

Hello Everyone,

Last month, we asked for input from the IRIS community regarding exam topics for our InterSystems IRIS SQL Specialist and Expert exams. We will close the window for providing feedback on the exam topics on Thursday, August 31st, 2023. Thus, if you would like to have your say in what topics are covered on the exam, this is your last chance!

1
0 191