#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?

Set tSC=..Adapter.Post(.tHttpResponse, , tP
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.

USER>DO##class(TEST.ARGTEST1).NewMethod1(1,2,3,4,5)
US
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
}

Through the c

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.

I have a use case, though, where in %OnBeforeSave I want to actually get the old version of the object (and, theoret

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】

  set x=##class(User.test).%New() // create a new object

  // prepare an image
  set file=##class(%File).%New("c:\temp\Mii.png")
  do file.Open("RUK\BIN\")
  for {
       if file.AtEnd=1 quit
       // Convert image to Base64 format in chunks of 1024 bytes
       set cnt=file.Read(1024)
       se
2
2 725
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.

I would expect that somekind

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 454
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

1.Initializing program that has user prompts to change starting nodes. This program contains the FOR nests to step through nodes. If the Global value is different then we move

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.

To get this view, we could search the code with regular expressions. However, it would be more convenient to have all the parameters used directly in a table after


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 521
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

{
Method TestMyMethod()
{
 do

3
0 448
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

Serializing l

1
0 649
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.

The SQL documentation says "Messages indicating that a rollback occurred, and errors encountered during the rollback operation are logged in the cconsole.log", but when I deliberately write co

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

XData DTL [ XMLNamespace = "http://www.intersystems.com/dtl]
{
<transform sourceClass='CSVtoHL7.Inputfile.RecordtargetClass='En

14
0 741
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.

set m = ##class(%Regex.Matcher).%New("(.+)\@(.+)\.(.+)")
do m.Operat
1
0 219
Question Martin Staudigel · Aug 28, 2023

Hello Community,

To get to my problem, I need to elaborate a bit. We use an older fixed length format called HCM to transfer data from our SAP-ISH system to the Intersystems server. The data file is generated on a dedicated server and stored in a directory that is mounted to the communication server.
The synchrnoization is done via a lock file, which is exclusively locked in the adapter.
Now this, let's call it HCM server, is to be replaced. The old server is a CentOS 6.4 (Final) (uname -rv: 2.6.32-358.14.1.el6.x86_64 #1 SMP Tue Jul 16 23:51:20 UTC 2013), the new server is a SLES15.5 (uname -rv




4
0 260
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 3113
Question AndreClaude Gendron · Apr 19, 2016

We are trying to create a simple class extending %RegisteredObject that could be used as a singleton. However we are not able to store it in a global to later be retrieved (by the same process but elsewhere in the code).

I resumed my issue in this small code sample : 

ClassMethod RunMe()
{
   // Create a simple %RegisteredObject
   set obj = ##class(%ZEN.proxyObject).%New()
   set obj.MyProp = 22
   do ##class(%SYSTEM.OBJ).Dump(obj)
   
   // Store it in a global
   set ^MyGlobalName = obj
   write "Stored : " _ obj,!!
      
   // Retrieve it from the global
   #Dim obj2 As %ZEN.proxyObject = ^MyGlobalNam

8
0 1075
Question Jack Broomhead · Aug 17, 2023

Hi, 

I'm currently looking to deploy a production with readymade auditing functionality. I can currently call user defined audit entries using $SYSTEM.Security.Audit() but I'm finding to display these posts properly I need to create User-Defined Audit Events on the management portal, otherwise they are displayed as "UserEventOverflow"/"AddedUnknownUserEvent" . My question to the community is, is it possible to create the User-Defined Audit Events (found in System > Security Management > User-Defined Audit Events) programmatically (and how can this be achieved) rather than manually creating t

1
0 230
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!

To show our appreciation for helping us validate our exam design, we will hold a raffle where 15 survey respondents will be chosen to receive a $50 gift card. The gift card is a Tango Card that can be redeemed at any number of online retail

1
0 191