ObjectScript

Syndicate content 30 

There are some classes in our code base that contain Methods only (no properties). I told my colleagues that converting them into the ClassMethods should improve performance as it would eliminate unnecessary OREF support at run-time. Some of them replied that it would be microseconds, so what is the reason to bother.

Is it possible to estimate the impact of OREF support of method calls at run-time? E.g., as a % of all CPU load. 

Last answer 1 October 2018 Last comment 2 October 2018
0   0 4
296

views

0

rating

The following class method "test" contains code that can create a new class, create new properties for classes, or create new methods for classes. "test" runs all three of these processes once, and the code that performs each action is labelled by comments in the method:


ClassMethod test() As %Status
{
    set sc = $$$OK
    
    // Create a class
    set class = ##class(%ClassDefinition).%New("MyClass")
    set class.Description = "This is my test class"_$c(13,10)_"testing %ClassDefinition"
    set class.Super = "%Persistent"

    // Create a property and add it
    set property = ##class(%PropertyDefinition).%New("MyClass.MyProperty")
    set property.Type = "%String"
    set property.Description="This is a property"
    set sc1 = class.Properties.Insert(property)
    do:$$$ISERR(sc1) $system.Status.DisplayError(sc1)
    set sc = $$$ADDSC(sc, sc1)
    
    // Create a method and add it
    set method = ##class(%MethodDefinition).%New("MyClass.MyMethod")
    set method.ReturnType = "%Integer"
    set method.FormalSpec = "x:%Integer,y:%Integer=10"
    set method.Description = "Return product of x and y"
    set method.CodeMode = "code"
    set method.Code = " new result"_$c(13,10)_" set result=x*y"_$c(13,10)_" quit result"
    set sc2 = class.Methods.Insert(method)
    do:$$$ISERR(sc2) $system.Status.DisplayError(sc2)
    set sc = $$$ADDSC(sc, sc2)
    
    // Save the class definition
    set sc3 = class.%Save()
    do:$$$ISERR(sc3) $system.Status.DisplayError(sc3)
    set sc = $$$ADDSC(sc, sc3)
    
    return sc
}

Here's a link to the code on GitHub

Last comment 27 September 2018
0   0 3
210

views

0

rating

HI,

I am a newbie so excuse my basic questions.

I have installed Caché on Mac Os High Sierra 10.13.6 and have started the ObjectScript tutorial but I cannot open Terminal in Caché.

The instructions provided on the tutorial don't appear to be for Mac OS as there is no cube icon:


n order to begin practicing using ObjectScript, you need to start the Terminal. Click the Caché cube iconin the task bar and select Terminal from the menu. This brings up the terminal window, and you can see from the prompt that we are in the USER namespace. Namespaces are logical directories, containing routines (programs) and globals (data).

So my question is how do I open the terminal window in Caché, I have navigated to the user and samples  directory in Terminal window but the ObjectScript commands  are not recognised

Last answer 21 September 2018 Last comment 22 September 2018
0   0 4
211

views

0

rating

The following code snippet includes a class method "test" that runs code to find a class based on the class's name. "test" takes one argument, which is the name of the table:


Class objectscript.findTable Extends %RegisteredObject
{
    classmethod test(name as %String="mytable")  
    {
            #Dim result as %ResultSet
            #Dim tName as %String
            #Dim contain as %Integer
     
            Set contain=0
            Set result = ##class(%ResultSet).%New("%Dictionary.ClassDefinition:Summary")
            Do result.Execute()

            While(result.Next()) 
            {
                Set tName=$get(result.Data("Name"))
                &sql(select position (:name in :tName) into :contain)
                Write:contain'=0 tName, " ... ", name, " (", contain,")", !
            }
            Return $$$OK
     }
}

Here's a link to the code on GitHub

Last comment 21 September 2018
+ 1   0 4
280

views

+ 1

rating

This code snippet determines the day of the week associated with a date. The class method "test" takes a date as a string in "mm/dd/yyyy" format, and returns an integer corresponding to a day of the week:


Class cartertiernan.getDayfromDate Extends %RegisteredObject
{
    classmethod test(date) as %Integer {
        //Set date = $ZDATE(date) //  Looks like: mm/dd/yyyy
     
        Set monthList = $LISTBUILD(0,3,3,6,1,4,6,2,5,0,3,5) // (Jan,Feb,Mar,Apr,...)
        Set centuryList = $LISTBUILD(6,4,2,0) // first two digits divisiable by 4, then subsequent centuries. EX (2000, 2100, 2200, 2300)
        Set dayList = $LISTBUILD("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") // Index goes from 0-6
         
        Set day = $PIECE(date,"/",2) // get the day 
        Set monthVal = $LIST(monthList,($PIECE( date,"/",1 ))) // get the month value
        Set first2DigsYear = $PIECE( date,"/",3 ) \ 100 // get the last 2 digits of the year
        Set last2DigsYear = $PIECE( date,"/",3 ) # 100 // get the first 2 digits of the year
         
        // Used for DEBUG perpouses
        /*write !,"day: ",day
        write !,"Month: ",monthVal
        write !,"last2: ",last2DigsYear
        write !,"first2: ",first2DigsYear
        write !,"cen Val: ",$LIST(centuryList,(first2DigsYear # 4) + 1),!!*/
         
        // Look here for formula explination (its the "Basic method for mental calculation")
        // http://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week
        Set dayOfWeekVal = ( day + monthVal + last2DigsYear + (last2DigsYear\4) + $LIST(centuryList,(first2DigsYear # 4) + 1 ) ) # 7
     
        Quit dayOfWeekVal
    }
}

Here's a link to the code on GitHub

(originally posted to CODE by Carter Tiernan, 6/18/14)

Last comment 20 September 2018
0   0 2
130

views

0

rating

Hello Experts,

I have a silly question of using InsertParam method and usage. I understand it is name value pair. I am using GET method to send a url and to get the details from server. URL has multiparameter

URL -  api/Identifier/Image/?Verify.EDD={EDD}&Verify.Ethnicity={ETHNICITY}

I have used the URL in a method and called that method directly in the business operation. I am using Insertparam method -

do httpRequest.InsertParam("EDD",..Data.Verify.EDD)
do httpRequest.InsertParam("ETHNICITY",..Data.Verify.Ethnicity)

where httpRequest is an object of %Net.HttpRequest class

Question is how will these parameters can be called in the URL? Please advice

Last answer 20 September 2018
0   0 2
0

comments

83

views

0

rating

I am trying to create a file from within a zen page but it keeps giving me a method does not exist error

in my page, i am taking the values and writing them to a file, when I do this :

 set filename= ##class(%Library.File).New("E:\test\file.txt") it gives me an error

Would appreciate some guidance on this.

Last answer 18 September 2018 Last comment 18 September 2018
0   0 2
103

views

0

rating

We have the need to write a function that can loop through say a field in an OBX segment within HL7 and compare it to a string passed. Is it possible to have the user enter the Operator ( >,<,=,<>) as a variable inside Cache object script? Does anyone have any examples they can share?

Thanks

Scott Roth

The Ohio State University Wexner Medical Center

Last answer 17 September 2018 Last comment 14 September 2018
0   0 5
164

views

0

rating

Hi,
it is possible to convert a csv file to json file?

I want to stream json files and output the data as it comes in from the files. So my files are "csv" type and I want to convert these files to "json" type.


I can read csv file as follows:

ClassMethod ReadFile()
{
    set stream = ##class(%Stream.FileCharacter).%New()
    set sc = stream.LinkToFile("*.csv")
    do stream.Rewind()
    while'stream.AtEnd {
        set line=stream.ReadLine()
        write line,!
}

What should I add to convert it to "json" and read it again?

Thank you

Last answer 6 July 2018 Last comment 14 September 2018
0   1 5
495

views

0

rating

Hi,

I have a routing rule that calls some utility classmethods, but for some reason the compiled version insists on linking to a utility function in a different package.

The call to 'SendToEaling(HL7)' in  isn't compiling to a call to the LNWTIEPackage as expected:

##class(LNWTIEPackage.RoutingRules.Utility).SendToEaling((pContext.HL7))

but is instead becoming a call to the LNWDeploy package

##class(LNWDeploy.RoutingRules.Utility).SendToEaling((pContext.HL7))

Specifically 

<assign property="@SendToEaling" value="SendToEaling(HL7)"></assign>

 gets compiled to

set tTempVars("SendToEaling")=##class(LNWDeploy.RoutingRules.Utility).SendToEaling((pContext.HL7))

Any ideas what could be causing this?

Kind regards,

Stephen

RoutingRule

Last answer 7 September 2018 Last comment 6 September 2018
0   1 2
101

views

0

rating

This code snippet allows for a file on the web to be saved into the file system. Specify the server and GET request, as well as the directory the file should be saved to. The class method "test" runs the code:


Class objectscript.saveFileHTTP Extends %RegisteredObject
{
    classmethod test() {
        Set httprequest = ##class(%Net.HttpRequest).%New()
        Set httprequest.Server = "docs.intersystems.com"
        Do httprequest.Get("documentation/cache/20172/pdfs/GJSON.pdf")
        
        Do $System.OBJ.Dump(httprequest.HttpResponse)
         
        Set stream=##class(%FileBinaryStream).%New()
        Set stream.Filename="c:\test.pdf"

        Write stream.CopyFrom(httprequest.HttpResponse.Data)
        Write stream.%Save()
    }
}

Here's a link to the code on GitHub

+ 1   0 2
0

comments

168

views

+ 1

rating

This code snippet changes all passwords in a system to a specified string. The two literal strings at the beginning of the snippet can be adjusted to edit the system or password string. The class method "test" runs the code:


Class eduardlebedyuk.changePasswords Extends %RegisteredObject
{
    ClassMethod test()
    {
        set ns = $namespace
        zn "%SYS"
        set NewPass = "NewPassString"
        set rs=##Class(%ResultSet).%New("Security.Users:List")
        set st = rs.Execute()
        while rs.Next() { set st=$SYSTEM.Security.ChangePassword(rs.Get("Name"),NewPass)}
        zn ns
    }
}

(Originally posted on Intersystems CODE by @Eduard Lebedyuk, 10/8/2014

Last comment 3 September 2018
0   0 4
188

views

0

rating

Hello,

Currently, I'm working with a Java Gateway, and I have the following problem. When importing a class into IRIS, which uses methods from a generic class, I can not find the general methods I need. I'm talking about the test2 method from the class test. How can I import the java method that returns a generic?

Last answer 30 August 2018
0   0 3
0

comments

102

views

0

rating

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 language, this experience is too "fresh" for us to accurately estimate the severity/time to fix of such issues. The list of rules, along with their severity and time to fix can be found here

Last answer 5 April 2016 Last comment 28 August 2018
+ 5   1 7
908

views

+ 5

rating

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

Last answer 26 August 2018 Last comment 25 August 2018
0   0 4
982

views

0

rating

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 methods

Last answer 22 August 2018 Last comment 23 August 2018
0   0 5
167

views

0

rating

Traditional Caché Objectscript has the multi-dimensional array as its main form of complex data structure and the $order command as the main means of traversing said data structures. But newer versions of Caché ObjectScript also have data structures that are direct parallels of what languages such as JavaScript provide, in the form of %DynamicObject and %DynamicArray. These have an easy to use iterator feature via the %GetIterator method, and even a handy built-in literal syntax for constructing new objects.

Given all these nice features, are there any disadvantages to using these fancy new features? I imagine performance might not be as fast and memory usage might be a bit higher compred to plain old arrays. And of course, this makes the code not backwards compatible to older versions of Caché which did not have these features. Are there any other caveats I should be aware of?

Last answer 15 August 2018 Last comment 16 August 2018
0   0 5
208

views

0

rating

Good afternoon everyone,

I hope you are well,

I am currently working on the below opportunity and if anyone here would like to hear more details please feel free to contact me on 01908 886 030 or teo.rusu@identifiglobal.com

Met with the client yesterday, beautiful office in Waterloo London, latest tech available with many benefits including working from home 2 days/w as well!

Intersystems Caché Senior Software Engineer

London

Salary up to £75,000 (negotiable  for the right candidate)

An exciting Software as a Service company creating enterprise software used by 33,000+ people globally. They provides a secure, global cloud platform marketing teams use to rapidly expand services across channels and launch into new markets

+ 3   1 2
0

comments

210

views

+ 3

rating

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 was submitted. I tried using a custom outbound adapter with a DEBUG=2 but I had no idea where the request and response are written. I did not see them in the HTTP Trace log of the CSP gateway after turning on the TRACE.

2: How is the Adapter password set? I tried the following 3 ways and they all returned an "unauthorized" error.

Did not work:

Last answer 31 July 2018 Last comment 29 July 2018
0   0 3
235

views

0

rating

Hi,

is there a way to tell Caché to ignore the order of elements when hosting a SOAP-based webservice?

At the moment I keep getting the Error-Code #6237 (Unexpected tag in XML input) when the request is not in the exact same order as defined.

Looking forward for your answers.

Regards,

Thomas

Last answer 30 July 2018 Last comment 31 July 2018
0   0 2
139

views

0

rating

I am using java gateway imported/proxy classes and JG business service. I need to load a dll at run time.

I use System.loadLibrary/System.load when in java. I’ve tried $ZF(-3,” C:\Windows\System32\pteidlibj.dll”) and $ZF(-4,1,"C:\Windows\System32\pteidlibj.dll") but I’m getting <DYNAMIC LIBRARY LOAD> error.

How can I load a dll at run time using COS?

Last comment 6 May 2016
0   0 3
592

views

0

rating

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?

Last comment 18 July 2018
0   1 15
1397

views

0

rating