#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 Arto Alatalo · Feb 21, 2019

I'm getting this compilation error:

Kompilieren der Klasse digi.packet
FEHLER #5002: Caché-Fehler: <FUNCTION>zLockUse+5^%ExtentMgr.GlobalRegistry.1
  > FEHLER #5030: Während der Kompilierung von Klasse 'digi.packet' ist ein Fehler aufgetreten

when importing one of my classes on the production server into one particular namespace:

8
0 828
Question Daniel Lee · Feb 22, 2019

In my routine when I call set filestream.FileName = filename, I get an error

"cn_iptcp://localhost:56773/USER/%Stream.FileBinary.1.INT" does not exist on the Server

I successfully instantiate the %Stream.FileCharacter object. 'filestream' value is '1@%Stream.FileCharacter'. But when I debug the code, the step where I try to set the file name fails. 

The port number for local host looks good for my current instance. I have tried a few variations, such as using the method FileNameSet(). But this did not work either. 

10
0 750
Question Daniel Lee · Feb 18, 2019

I am new to Intersystems Cache, so please bear with me. We are using HealthShare 2013.1. 

I have a routine to compare databases from separate instances where I want to ignore values that begin with %sqlcq. I thought this would be easy with pattern matching operator '?' but it is proving difficult and it seems to be because of the percent character. 

For example:

set x = "%sqlcq.something.value.foo"

#;does not evaluate as true. 
if x?1P1"sqlcq" {write "valid"}

set y="sqlcq.something.value.bar"

if y?1"sqlcq".E {write "valid"}
valid
if x?1"sqlcq".E {write "valid"}

  
4
0 564
Article Robert Cemper · Feb 8, 2019 2m read

The Caché / Ensemble standard distribution contains in namespace SAMPLES
a nice example of a CSP page consuming WebService as a Client.
I have modified it not only to display the replies but to feed them back into a Global.
I used the classic Hyperevent to achieve this. The replies end up as a log in global^WSREPLY.
When there is no input anymore the page closes and goes away.

There are 2 versions with visible and hidden display during operation.
dc.WSCSP.reverseVerbose.cls and dc.WSCSP.reverseHidden.cls

The message to send is simply passed as a hash after the CSP_URL. (Mind URL encoding!)

0
0 623
Question Laura Cavanaugh · Feb 5, 2019

Our development server is set up to automatically keep the .INT code of compiled classes and routines, but the live servers are set to not keep the .INT code.

I know how to set the system to keep this code ($SYSTEM.OBJ.SetQualifiers() ?)  but what are the ramifications of keeping this code on the live servers?  Is it just a space issue?  I always thought it was to keep the code more private.

4
0 712
Question Stephen De Gabrielle · Feb 1, 2019

Hi,

I'm writing to an ODBC connection to a SQLserver database, and I seem to be sending the wrong data type to a date colum?

set tSC = ..Adapter.ExecuteUpdate(.intRows,sqlInsert,$ZDATETIME($NOW(),3,2), pRequest.ComposerName, [...])

I think  `$ZDATETIME($NOW(),3,2)` is ODBC datetime format: 

https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_fzdatetime#RCOS_fzdatetime_tformat

Do I have it wrong?

Stephen

3
0 614
Question Eduard Lebedyuk · Jan 26, 2019

Today in docs I found this example using NULL:

 WRITE $LISTVALID($LB(NULL)),!

simplified

zzdump $LB(NULL)

and NULL can be case-insensitive:

zzdump $LB(null)

seems the same as just:

zzdump $LB()

But if null variable is defined then list would contain value from variable. Case sensitive in that situation.

Does anyone have any Idea what is this? Is NULL used anywhere besides as a list element?

5
0 437
Article Eduard Lebedyuk · Jan 23, 2019 3m read

Recently I needed a classmethod that returns annotation value based on a name of a activity.

As doing it at runtime seemed inefficient, I wrote compile-time utility that iterates over all business process activities and generates relevant code.

This code could be used in a variety of situations when you need to iterate over business process activities, just add it as a secondary superclass to your BPL processes.

2
1 500
Question Dhaval Shah · Jan 17, 2019

Let Say I have 
Class Carrier Extends %Persistent

Property Employee As Array of Class Employees

Class Employees Extends %SerialObject

Property Name As %String

Property Address As Array of Class AddressDetail

Class AddressDetail Extends %SerialObject

Property Street1 As %String

Property Street2 As %String


I can get value for Employee Name  as Employee_Name.

But I want to Get Value of Address Street1 and Street2 of Class AddressDetail using SQL Query
How can I get that?

3
0 489
Question Kevin Furze · Jan 16, 2019

I need to automate the handling of usernames passwords, serverNames etc for use in the sending and receiving  of emails, logging into SFTP servers etc etc for use within COS code
To manage external passwords we could use LastPass or any other proprietary password loggers, but I need to be able to call them as part of the automation (COS code) and occasionally visually look them up to "remind" the staff of their passwords.

any suggestions as to the best class data constructs to handle this scenario. Should the whole table be encrypted, only the passwords etc.

9
0 619
Article Gevorg Arutiunian · Jan 11, 2019 2m read

This code snippet sends an XML request to a server and saves the response to a file. The class method "test" runs the code:


Class objectscript.postXML
{
	classmethod test() {
		Set HTTPRequest = ##class(%Net.HttpRequest).%New()
	    Set HTTPRequest.ContentType = "text/xml"
	    Set HTTPRequest.NoDefaultContentCharset = 1
	    Set HTTPRequest.Location = "ITOMCZ"
	    Set HTTPRequest.Server = "wph.foactive.com"
	    Do HTTPRequest.RemoveHeader("User-Agent")  
	    Do HTTPRequest.RemoveHeader("Accept-Encoding") 
	    Do HTTPRequest.RemoveHeader("Connection")
	    Do HTTPRequest.SetHeader("Expect","100-continue")
    Set RequestXML = ##class(%Library.File).%New("c:\test.xml")
    Do RequestXML.Open("RS")
    Do HTTPRequest.EntityBody.CopyFrom(RequestXML)
    Do RequestXML.%Close()
 
    Do HTTPRequest.Post(HTTPRequest.Location)
 
    Do $System.OBJ.Dump(HTTPRequest)
    Do $System.OBJ.Dump(HTTPRequest.HttpResponse)
 
    Write HTTPRequest.HttpResponse.Data.Size
    Write HTTPRequest.ContentLength
 
    Set ResponseStream = ##class(%Stream.FileBinary).%New()
    // Second part is typically the file extension, i.e.: application/pdf -&gt; pdf
    Set FileType = $Piece(HTTPRequest.HttpResponse.GetHeader("CONTENT-TYPE"),"/",2)
    Set ResponseStream.Filename = "C:\test."_FileType
 
    Write ResponseStream.CopyFrom(HTTPRequest.HttpResponse.Data)
 
    Write ResponseStream.%Save()
    Do ResponseStream.%Close()
}

}

Here's a link to the code on GitHub

0
0 972
Question Michael Davidovich · Jan 3, 2019

Hello,

I have some beginner questions as I am working through the InterSystems Cache learning path:

- Where I work, we us Cache, but we often learning about and train on MUMPS.  No one really talks about or mentions MUMPS here, but my understanding is that ObjectScript is basically MUMPS plus whatever new things InterSystems put on top of it.  Is that a fair assessment?

- The training online often refers to IRIS.  We don't use IRIS, but we use globals to store data.  I suppose I'm just confused on the difference between Cache, Zen, IRIS and other products as they all seem to do similar things.  

16
0 924
Question Scott Roth · Dec 21, 2018

Has anyone called any outside Javascript code from inside their class files? I asked a long time ago if there was a way to manipulate an image within Cache Object Script, and since Cache doesn't have any image libraries its not really possible. However I have found Javascript to resize an image and wonder how hard it would be to mesh the two together.

Can anyone share any examples?

Thanks

Scott

9
1 1693
Question Chip Gore · Jan 2, 2019

Hi -

I'm wondering if anyone has coded up a means to create an extension for a %Persistent class from a base class to a sub-class without making a ton of assumptions about the Global structure. I'm trying to create a new "extension" record that would have the same ID as the Base Class 

Class BaseRecord Extends %Persistent

and

Class SubRecord Extends BaseRecord

where I would have an instance of a "BaseRecord" and I want to turn it into a "SubRecord" instance and have all of the existing references to the BaseRecord survive.

7
0 580
Article Gevorg Arutiunian · Dec 27, 2018 2m read

The following code walks a DOM using %XML.Node. It also prevents %XML.Writer to change whitespace. Run the code using the class method "test":


Class objectscript.walkDOM Extends %Persistent
{
	ClassMethod dfs(node As %XML.Node)
	{
	    s entrynode=node.NodeId
	    do {
	    //element nodes with one whitespacetyped child are the ones we want to change
	    if (node.NodeType=$$$xmlELEMENTNODE){
	        s snode=node.NodeId     
	        if (node.MoveToFirstChild())            
	            {
	                i ('node.MoveToNextSibling()){
	                    i (node.NodeType=$$$xmlWHITESPACENODE){
	                        s node.NodeType=$$$xmlTEXTNODE
	                        s node.NodeId=snode
	                    }
	                }
	        }
	        s node.NodeId=snode     
	    }   
	    if (node.HasChildNodes()){
	        d node.MoveToFirstChild()
	        d ..dfs(node)
	    }
	    } while (node.NodeType'="" && node.MoveToNextSibling())
	    s node.NodeId=entrynode
	     
	}
	 
	ClassMethod test()
	{
	  set xml = "abcdefg<![CDATA[   ]]>"
	 
	  s reader=##class(%XML.Reader).%New()
	  do reader.OpenString(xml)  
	  set writer = ##class(%XML.Writer).%New()
	  //do some magic
	  d ..dfs(reader.Document)
	   
	  w !,"with indent=1:",!
	  set writer.Indent = 1
	  do writer.OutputToString()
	  do writer.Document(reader.Document)
	  w writer.GetXMLString()
	  set writer.Indent = 0
	  w !,"with indent=0:",!
	  do writer.OutputToString()
	  do writer.Document(reader.Document)
	  w writer.GetXMLString()
	}
}

Here's a link to the code on GitHub: https://github.com/intersystems-community/code-snippets/blob/master/src/cls/objectscript/walkDOM.cls

0
0 418
Article Sergey Mikhailenko · Jan 23, 2018 20m read

This article was written as an attempt to share the experience of installing the InterSystems Caché DBMS for production environment. We all know that the development configuration of a DBMS is very different from real-life conditions. As a rule, development is carried out in “hothouse conditions” with a bare minimum of security measures, but when we publish our project online, we must ensure its reliable and uninterrupted operation in a very aggressive environment.

##The process of installing the InterSystems Caché DBMS with maximum security settings

OS security settings

2
5 1915
Question Anthony Filaski · Dec 14, 2018

Hello,

I'm looking to find if there is a datatype convert equivalent in Object Script to SQL convert function. Have a VarBinary string coming in from source application (which is really performing a SQL dump). The source application uses the standard SQL convert function to convert from varchar to varbinary on their side.

I know &sql(Convert()) should work in Object Script, but am wondering if there is a better way of doing this. 

Getting data in via flat file (Record Map), then using data transform to transpose this data to SDA3. 

4
0 1034
Announcement Evgeny Shvarov · Dec 16, 2018

Hi Community!

We try a new approach to the InterSystems Developers YouTube Videos called "Coding Talks"!

Coding Talks is a short video in which the developer demonstrates a particular feature or functionality of InterSystems Data Platforms which he/she uses to in coding. Typical format: the face on side and editor with ObjectScript.

Check this video I made by myself participating in Advent of Code 2018 and coding with InterSystems ObjectScript in VSCode.

Coding Advent of Code 2018 Using InterSystems ObjectScript 

0
1 412
Question Justin Wilson · Dec 8, 2018

I have a persistent class that represents cities across the United States.  It is below, but basically has a City Id, Name, Lat, Lon and a few other unimportant fields for this issue.  Anytime I attempt to query on the Latitude or Longitude it immediately returns no results.  My first thought was that it was a casting issue so I tried casting both sides to floats, ints, even strings and in all cases it immediately comes back with no results.  I then decided to cast it to a string and attempt a like statement thinking it might be something about how floats are handled, but still no joy.  Any

2
0 452
Announcement Dmitry Maslennikov · Nov 28, 2018

Are you ready for the next Advent of Code this year?

Just a few days left, the first puzzles will unlock on December 1st at midnight Eastern Time.

Not sure if I will manage to find time to solve those puzzles as quickly as last year, but hope some of you will do. We still have our leaderboard, you can join 130669-ab1f69bf.  So, we will see who the best.

4
0 588
Article Sean Connelly · Nov 19, 2018 2m read

Here's a fun test to see how well you know ObjectScript.

What will each of the following statements output?

write 5 * 10 + 1

write 1 + 5 * 10

write 1 + 0 / 10

write 0 && 0 = 0

write 0 = 0 && 0

write 1 && 1 = 1

write 1 = 1 && 1

write 2 && 2 = 2

write 2 = 2 && 2

write "1 APPLE" + "2 BANANAS"

write "-1" + "1-2"

write +"+-+-+-5"

write "1D7P"-1

write "1E6F"-1

write 0 = "FOO"

write 0 = +"FOO"

write 0 = ''"FOO"

write "10X" - " 5" - "5"

write "10-5"

write +"10-5"

write @"10-5"

write 5_"1"-1

write "5"-1_"1"

write 10 + 10 > 21 + 1

13
2 1226
Discussion John Murray · Mar 3, 2016

Is anyone in the fine community of developers who work with ISC technologies looking at Microsoft's Visual Studio Code offering?

One of Bill McCormick's recent posts about Atelier referred to Visual Studio being considered the best IDE. Granted, Code is far less of a tool than VS, and probably always will be. But it claims to be open source and cross-platform, i.e. Linux and OS X as well as Windows.

I'm not 100% sure my post belongs in the Atelier group, but didn't see any other group that would be a better home.  Might we benefit from a "Tools" group?

26
3 5299