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

Discussion Francis Galiegue · Apr 4, 2016

Hello community!

At the global summit in Phoenix, we (Lite Solutions) will be presenting a tool performing static code analysis on ObjectScript source files. You can see it in action at this URL:

https://demo.cachequality.com

Technically, the tool is a language plugin over SonarQube (http://sonarqube.org) and consists of three main parts:

  • parsing the language,
  • collecting metrics,
  • collecting issues.

The third point is where we kindly request for feedback.

Explanation: issues are the result of rules being triggered by inspecting the source files. But while we do have some experience with the l

6
1 2165
Question Mack Altman · May 26, 2016

Does anyone have any experience with getting, unfortunately, an older version of Cache to authenticate via SMTP to send email? I have verified that the settings are set up properly on the mailbox as I have successfully sent an email from a LAMP server, which comes from the same IP address.

If you have any thoughts, I would greatly appreciate it.

This is the error I receive

ERROR #6034: SMTP server connection failed during MAIL FROM command: <READ>zSend+105^%Net.SMTP.1.

when I run the following.

S() Public {
server=##class(%Net.SMTP).%New()
server.smtpserver="smtp.office365.com"
server.port="58


6
0 2738
Question Jack Huser · Aug 22, 2018

Hello Everyone,

I was wondering about the best way to initialize several variables, or several lists of variables.

Would it be better to write it like:

set (var1, var2, var3) = "value1"
set (var4, var5) = "value2"
set (var6,var7,var8) = "value3"

or

set var1="value1", var2="value1", var3="value1", var4="value2", var5="value2", var6="value3", var7="value3", var8="value3"

or

set var1 = "value1"
set var2 = "value1"
set var3 = "value1"
set var4 = "value2"
set var5 = "value2"
set var6 = "value3"
set var7 = "value3"
set var8 = "value3"

When comparing the speed of each metho

6
0 613
Announcement Daniel Tamajon · May 21, 2018

As a developer, usually I'm concerned about how my code health is, and how the other coders code can affect to my own work.  And I'm quite sure most of us feel very similar.

In our company we use a Static Code Analysis tool to analyze code for different languages to ensure we are writing high quality and easily maintainable code by following a few best practices in terms of code structure and content. And the question was: why should be different for Caché ObjectScript language?

3
4 1233
Question Stella Ticker · Jul 20, 2018

The REST webservice works perfectly when run on SOAP UI. This end point server is an https site that uses basic authentication (uname and pwd).  But when I run the request through an Enslib.Rest.Operation using a configured SSL and stored credentials, I get an "unauthorized" error, unless I explicitly hard code the password in the operation class. HS Version is 2014.1 .

I have 2 questions. Pardon me, they are both related!!

1: How can the httprequest object be viewed in Ensemble? It took a long time for me to actually troubleshoot this because I had no way to see the httprequest object before it

4
0 1234
Article Benjamin Thorne · Jul 24, 2018 1m read

The following code allows a user to view the audit settings of their instance. Run the code by running the class method "test":


class objectscript.checkAudit Extends %RegisteredObject
{
	classmethod test() {
		w "Checking for Auditing...",!
		Set SYSOBJ = ##class(Security.System).%OpenId("SYSTEM")
		If +SYSOBJ = 0 Set SYSOBJ = ##class(Security.System).%New()
		i SYSOBJ.AuditEnabled {
			w "Security Auditing is enabled for the following services",!
			s rs=##class(%ResultSet).%New("Security.Events:ListAllSystem")
			s sc=rs.Execute()  If $$$ISERR(sc) Do DisplayError^%apiOBJ(sc) Quit
			while r
1
1 770
Discussion Evgeny Shvarov · Apr 22, 2018

Hi, Community!

Have a question for general discussion. 

In ObjectScript we have cls for classes and mac code, which both compile into int code. 

Is there any reason when you use mac instead of cls  for non-persistent classes?

For me the benefits for cls are:

1. Inheritance and other OOP features

2. Auto-documented code 

For mac one visible benefit is easier call in terminal:

do method^Utils(p1,p2)

vs

do ##class(Package.Utils).method(p1,p2)

What is your choice and why?

43
1 3054
Question Laura Cavanaugh · Jul 12, 2018

I have a class that has a property calledTags (like DescriptiveWords, but tags), where multiple tags are possible.  I am trying to decide on list of Objects vs. array of Objects.

Based on this post: https://community.intersystems.com/post/querying-list-property-sql, sounds like using an array of Objects is the better way to go. Indeed, I already noticed that it's not possible to have duplicates when using an array of Objects.

However, I am unable to make my queries on the array of Object use an index.  

Here is a code example, with queries and the cost of the query (see the comments for each Inde

4
0 974
Question Jasenko Donlagic · Jul 3, 2018

Hi everyone,

I am still learning the platform for a student project and have to do some streaming and data analysis next. Since for my case I have no "live api" I wanted to just stream json files and output the data as it comes in from the files. (basically to emulate a incoming data scenario)

So thanks to the documentation and community posts I have figured how to create a stream and read data from a JSON but since I'm also new to JSON I have some parsing problems. I don't know how to access subarrays/sub-objects via objectscript.

The structure of the JSON File, I will omit some data becau

2
1 2941
Question Stephen Wilson · Aug 8, 2017

I came across this behaviour when debugging some Cache ObjectScript code.  I have provided a simple example below.

Example 1:

START
 ZBREAK /TRACE:ON:"C:/temp/zbreak_trace.log"
 ZBREAK *VAR1:"T"
 ZBREAK *VAR2:"T"
 ZBREAK *VAR3:"T"
 Set (VAR1,VAR2,VAR3)=""
 Kill VAR1,VAR2,VAR3
 Quit

Trace Output:

Trace: ZBREAK SET VAR3="" at START+5^TRACE

Trace: ZBREAK KILL VAR1 at START+6^TRACE

Trace: ZBREAK KILL VAR2 at START+6^TRACE

Trace: ZBREAK KILL VAR3 at START+6^TRACE

$ZV value:

Cache for Windows (x86-32) 2017.1 (Build 792) Mon Mar 20 2017 20:20:07 EDT

Notice th

3
1 420
Question CM Wang · Jun 27, 2018

I am trying to read some binary data from a local file or through socket.

The binary data is like H.264 codec, I need to read data BYTE by BYTE (even BIT by BIT) and decide the next step based on the data read so far.

I check the documentation and it seems like most of the sample focus on human readable IO, ie: LINE by LINE.

Could I achieve my goal through COS?

Thanks. 

3
0 1492
Question Mack Altman · Jun 25, 2018

Typically, I have time to review the documentation, which I'm sure is here. However, I have a workaround (TEST1) but I was wondering if anyone could assist me in advising how I would need to adapt the curly brace snippet (TEST2) to provide the same result.

Thanks for any help you can provide.

TEST1(STATUS=1) K (STATUS)X "S MSG=$S(STATUS:""HELLO"", 1:""GOODBYE"")"W !,MSGQTEST2(STATUS=1) PUBLIC {X "S MSG=$S(STATUS:""HELLO"", 1:""GOODBYE"")"W !,MSG}
3
0 386
Question Ben Spead · Jun 12, 2018

I have a serial object:

Class EmbedObj Extends %SerialObject

which is stored as a  property of another object

Class ContainerObj Extends %Persistent

Property InnerObj As EmbedObj;

Property Foobar As %String;

Question:

From within the context of an instance of EmbedObj, how can I navigate to the containing instance of "ContainterObj" and find that value of its Foobar property?

Harder Question:  Is there a way I can do this as part of SQLComputeCode? (my EmbedObj has a Calculated property which now needs to depend on the value of property Foobar of the containing object).

Thanks in advance for any help o

8
0 760
Question Jason Parker · Jun 17, 2018

Hello,

If this question is in the wrong section, I apologise.

Has anyone ever used Cache Object Script to connect to any hardware such as a sensor?

What I mean is this :-

Lets assume that code has been written in Cache Object Script where it can detect breaks in electrical connections.

There is some sort of wire/cable that is plugged into the PC and then this wire/cable runs to say a house window or door and is connected to some sort of sensor, when the window/door is closed then the circuit is complete, when the window/door is open the circuit is broken and somehow Cache Object Script knows this a

2
0 328
Question Antonio Garcia Martinez · Jun 8, 2018

Hi,

I was wondering if there is any way to count elements from an array. I guess not as an array could be multi-dimensional and that would be a problem to return the number of elements inside the array.

As an example:

S a(1) = "blue"
S a(2) = "red"
S a(3) = "yellow"
w a.count() ==> 3

Information about arrays: https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KE…

Thanks

4
0 2164
Question Evgeny Shvarov · Jun 5, 2018

Hi, Community!

$CASE is a fine syntax sugar for "Ifs" with one-line/one-word expressions, like in docs:

SET daynum=$ZDATE($HOROLOG,10)
  WRITE $CASE(daynum,
              1:"Monday",2:"Tuesday",3:"Wednesday",
              4:"Thursday",5:"Friday",
              6:"Saturday",0:"Sunday",:"entry error")

But if my expression for a current case is a multi-line business logic? Can I use "{}" somehow or better go with "IF" instead?

13
1 643
Question ED Coder · May 16, 2018

Hi,

I'm trying to send emails to a distribution list but it doesnt work. However, When I send emails to individual emails it works fine. Is there a configuration that I need to be checking or enable?

I'm doing it within a Business Operation:

Set SendList="grouplist@email.com, eric@email.com"f a1=1:1:$l(SendList,",") s ToAdd=$p(SendList,",",a1) d  .Set Mailer = ##CLASS(%Net.SMTP).%New().Set Mailer.smtpserver = "10.xx.200.000".Set Msg = ##class(%Net.MailMessage).%New().Set Msg.From="manager@email.com.Do Msg.To.Insert(ToAdd).Set Msg.Subject = "Sample Email to distribution l
7
0 714