#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 Jamie Prevo · Jun 17, 2023

Sorry, somewhat of novice here, but how is a mac or a routine created into a binary or is there a way to hide your routines so that no other user can edit them?  Like remove source code and have an executable?

I would like to do this MAC and CSP pages

8
0 513
Article Alex Woodhead · Jun 20, 2023 2m read

Excuse if this is obvious to Python programmers but for those crossing over from ObjectScript this may be a useful tip.

The scenario is developing some Embedded python commands.

Testing out functionality is being confirmed via the shell:

$SYSTEM.Python.Shell()
 
Python 3.9.5 (default, Mar 14 2023, 06:58:44) [MSC v.1927 64 bit (AMD64)] on win32
Type quit() or Ctrl-D to exit this shell.
>>>

When Python evaluates an expression in the shell, it prints the result of the expression to the terminal.

>>> 1 + 2

3

It is quite easy to accidentally evaluate and print out values

0
0 294
Question Samantha Forish · Jun 16, 2023

I am working with a REST API JSON Response that contains a list of integers (departmentids).

JSON Response:

{
"status":"ACTIVE",
"departmentids":[
72
],
"subscriptions":[
{
"eventname":"LabResultAdd"
},
{
"eventname":"LabResultUpdate"
},
{
"eventname":"LabResultClose"
}
]
}

 

I am having trouble getting that to parse into my custom message structure using the %JSONImport method.

do pResponse.%JSONImport(tHttpResponse.Data.Read())

Here is my custom message class (pResponse):

1
0 298
Question Lorenzo Scalese · Jun 14, 2023

Hello!

I would like to find all classes not up to date in a namespace programmatically.

With IRIS Studio, we can see the single "+", but I don't know how to do that with a script.

Set sql = "SELECT ID, Name FROM %Dictionary.ClassDefinition WHERE NOT ID %STARTSWITH ?"Set params($Increment(params)) = "%"Set tResult = ##class(%SQL.Statement).%ExecDirect(, sql, params...)

If (tResult.%SQLCODE'=0)&&(tResult.%SQLCODE'=100) Set sc = $$$ERROR($$$SQLError, tResult.%SQLCODE, tResult.%Message) Quit sc

While tResult.%Next() {
    // if class not up to date ??
}
1
0 230
Question Yone Moreno · May 12, 2023

Good morning,

I was wondering:

Given the following scenario where we have a string where each two items are being splitted by "|" as follows: "squadName|initialLetter"

"Alfa|A|Bravo|B|Charlie|C|Delta|D|Echo|E|Foxtrot|F|Golf|G|Hotel|H|India|I|Juliett|J|Kilo|K|Lima|L|Mike|M|November|N|Oscar|O|Papa|P|Quebec|Q|Romeo|R|Sierra|S|Tango|T|Uniform|U|Victor|V|Whiskey|W|X-ray|X|Yankee|Y|Zulu|Z"

And we would need to generate a String structure like:
 

4
0 393
Question Evgeny Shvarov · May 13, 2023

Hi folks!

Those who actively use unittests with ObjectScript know that they are methods of instance but not classmethods.

Sometimes this is not very convenient. What I do now if I face that some test method fails I COPY(!) this method somewhere else as classmethod and run/debug it.

Is there a handy way to call the particular unittest method in terminal?  And what is more important, a handy way to debug the test method?

Why do we have unittest methods as instance methods? 

25
0 802
Article Hiroshi Sato · May 18, 2023 2m read

InterSystems FAQ rubric

Using the Config.Configuration class and SYS.Database class methods, you can create and register a namespace database from the terminal.

Below is a series of execution examples that create database file /CacheDB/AAA/cache.dat and register database AAA and namespace AAA in the configuration file (cache.cpf).
* Execute in the %SYS namespace. *

* Make sure that this script runs as the user  that is used for all IRIS processes to ensure that the directory has appropriate ownership and permissions *

3
0 535
Question Erum Ahsan · Jun 6, 2023

I have the following method call (have included html and css as well). when I debug the code in a browser, JavaScript seems to work fine. Loading image is coming up, table is getting hidden. But when I close the debug and just load the page and run it, loading image is not coming up, neither the table is hidden. Not sure what is going on? I need help to understand what I am doing wrong?

XData Style

{

<style type="text/css">

#loading {width: 100%;height: 100%;top: 0px;left: 0px;position: fixed;display: block; z-index: 99}

#loading-image {position: absolute;top: 40%;left: 45%;z-index: 100}

</style>

}

3
0 222
Article David Hockenbroch · Jun 2, 2023 5m read

We are looking at what we need to do to migrate from our current usage of Zen reports to InterSystems Reports. One of the hurdles for us is figuring out ways to interact with InterSystems reports programmatically from ObjectScript routines. There is a Java API for it, but it is possible to generate a report from InterSystems reports to a stream object in ObjectScript without diving into Java by using a %Net.HttpRequest. Here is a code example, followed by an explanation:

0
0 276
Question Thembelani Mlalazi · May 18, 2023

I am trying to call to a website that renders a xml structure as a response.if I put the url on the browser an xml rendered page is returned but if i call to this using the below code I get an object reference error which I am finding had to understand is there anyone who could help understand this error or point me in the right direction thanks.

Set tSC=$$$OK

2
0 400
Question Brendan Blackford · May 17, 2023

Hi,

I'm trying out VS Code with IRIS for Health 2023.2 (not available in above dropdown) in a local container.  I can open read-only files in the Objectscript viewer and have a local folder connected to the correct namespace.  However, when I make changes and try the "import and compile" option, I get:

ERROR #16006: Document <filepath> name is invalid

The first four chars of <filepath> appear to have been truncated

Here is my settings.json

{

    "security.workspace.trust.untrustedFiles": "open",

    "workbench.colorTheme": "InterSystems Default Dark",

    "intersystems.servers": {

4
0 556
Article Joel Solon · May 23, 2023 5m read

Methods written in ObjectScript can use pass-by-reference arguments to return information to the caller. Python doesn’t support pass-by-reference arguments, so Embedded Python in IRIS doesn’t support them either. That's it, that's the end of the post, hope you liked it. 😉 But wait, what about the Classic Rock & Roll?

1
1 636
Question Dmitrii Baranov · May 19, 2023

Example:

Method Execute (args...) As %Status {
...
 #dim statement as %SQL.Statement
 set statement = ##class(%SQL.Statement).%New(2)
 set statement.%Dialect = "CACHE"
 do statement.prepare(query)
    
 #dim rs as %SQL.StatementResult
 set rs = statement.execute(args...)

My questions are: 1) how do I get the size of **args **2) how to get all values of **args **3) is it possible to modify the args?

6
0 461
Question Elliott Grey · May 15, 2023

Trying to gather basic code examples written in ObjectScript and realized it's probably easiest to ask the people who know what they're doing!

I'm looking for examples of the following five prompts all in ObjectScript:

Prompt 1. Write a function that partitions the array into two subarrays: one with all even integers, and the other with all odd integers. Return your result in the following format:

[[evens], [odds]]

Prompt  2. Create a function that computes the hamming distance between two strings

Prompt  3. Make a function that encrypts a given input with these steps:

Input: "apple"

3
0 307
Question Ben Spead · Apr 12, 2023

I have a situation where I have a handful of classes which I need to copy to another Namespace (which uses a different RoutineDB) on the same instance, load it and compile it.

Can anyone help me come up with a command that will do this quickly and easily?   Perhaps something with extended reference?  

This is somewhat time sensitive so thank you in advance for your ideas!

23
0 1028
Article Evgeny Shvarov · May 16, 2023 1m read

Hi folks!

Just want to introduce you a new util to import CSV into IRIS - csvgenpy!

Install

USER>zpm "install csvgenpy"

Use:

do ##class(shvarov.csvgenpy.csv).Generate("file or url","table","schema")

Example:

USER>do ##class(shvarov.csvgenpy.csv).Generate("https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv","titanic","data")

This will create table and class data.titanic in IRIS and will load the data.  you can proof it with:

0
1 333
Question Stella Ticker · May 12, 2023

Has anyone had success with passing in a collections  property within a SOAP request to a Soap Service in Ensemble? Please reply with how you set up that collections property. I am able to successfully send a SOAP request correctly containing the elements of the collection property to Cache, as seen in a custom soap log file which I am using to troubleshoot. But the collection property in the  Ensemble request is not getting serialized, meaning MyContainers has nothing.

My.Request consists of a property, MyContainers, which can have 0 or more Containers (My.Container)

1
0 223
Article Robert Cemper · Feb 16, 2021 2m read

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.
1
2 1237
Question Elliott Grey · May 10, 2023

I'm trying to write an ObjectScript function that sorts version numbers to help learn ObjectScript. This is all I can think of after staring at VS Code for a while, but I don't know where to go with it. Can someone please help out with a tip? The goal is to take something like ["1.4.5", "0.5.3", "6.3.2", "1.2.4"] and turn it into ["0.5.3", "1.2.4", "1.4.5", "6.3.2"]

4
0 426
Question Anna Golitsyna · Apr 13, 2023

Is there any ObjectScript or a basic function that takes a string and separates it into words + punctuation/spaces array/list? Just not to reinvent the wheel. Say, process "It is a test, after all" into "It", space, "is", space, "a", space, "test", ", ", "after", space, "all". Or something to that effect.

9
0 444
Article Robert Cemper · May 9, 2023 2m read

Creating your own commands or shortcut is one of the strongest features of ObjectScript
If you create your own Language Extensions to ObjectScript you mostly have to find the
proper %ZLANGC00 or %ZLANGV00 or %ZLANGF00 and add the extensions manually.

A few utilities do it already automatically (ZPM, ZME, ..)
This utility allows you to add your extensions also programmatically.

  • eg. at first run, or during installation I found this quite useful for my Docker-based demos as it all happens at start time.

This package includes a demo example to visualize the operation of this utility.

How to Use it

0
0 552
Article Evgeny Shvarov · Oct 15, 2022 1m read

Hi Devs!

For me, one of the most painful things about ObjectScript is ##class(Class).Method() typing to call a class method in code or in a terminal. I even submitted an idea to simplify it in ObjectScript.

But! There is a new feature in VSCode ObjectScript that was just introduced to the plugin - Copy Invocation!

Just hover Copy Invocation link above every classmethod in a code, click on it and the invocation is copied to the buffer:

Paste it anywhere you want it to execute!

USER>w ##class(dc.sample.ObjectScript).Test()

Bazinga!

Here is the video that shows how it works.

7
2 762
Question Punit · Apr 24, 2023

I have a %GlobalBinaryStream object that I'm trying to save as a local file after being received through a SOAP Web Service.

To do this, I created a %Stream.FileBinary object and wanted to set where the stream copied to this object would be saved by using either the DefaultStreamDir() ClassMethod or the NewFileName() ClassMethod. However, the documentation isn't very helpful on how to use these ClassMethods.

Right now, I have the below code:

4
0 330
Question Ben Spead · Apr 25, 2023

I have a csp page that is using embedded Runtime Expression (https://docs.intersystems.com/ens201817/csp/docbook/Doc.View.cls?KEY=RC…) and within that expression I am using a $data() modulo 2 to look for root-level data elements (https://docs.intersystems.com/ens201817/csp/docbook/Doc.View.cls?KEY=RC…).

E.g:

#($select($data(^ImportantFlag)#2:"Important!",1:"Normal"))#

However, my modulo sign (#) after the $data() call is seen as the ending tag for the runtime expression resulting in a broken compilation.

3
0 242