Hi!
Did anyone try to serialize objects in Caché using Google Protocol Buffers? Your experience will be very helpful for me.
Thanks!
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.
Hi!
Did anyone try to serialize objects in Caché using Google Protocol Buffers? Your experience will be very helpful for me.
Thanks!
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
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
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)
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 -
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("ETHNICITY",..Data.Verify.Ethnicity)
Hi All, Can any one please tell how to get the Windows SID number using Caché Command.
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.

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
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
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(LNWDeployRoutingRules.Utility).SendToEaling((pContext.
d ##class(Test.Test).Test("hello") ; works perfectly
d ##class(Test.Test).Test("") ; does not work, the list stays empty
How can I do that. Thank you so much
Class Test.Test Extends %Persistent
{
Property ReviewedBy As list Of %String;
ClassMethod Test(val = "")
{
Set t = ##class(Forerun.Test).%New()
If val'="" Do t.ReviewedBy.Insert(val)
Else Do t.ReviewedBy.Clear() ;
$$$THROWONERROR(tSC, t.%Save())
Set id = t.%Id()
Set user = "me"
&SQL(UPDATE Test.
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
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?
Hi,
Does anyone know why the SYNTAX error appears?
Thanks,
Tomer.
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:
Technically, the tool is a language plugin over SonarQube (http://sonarqube.org) and consists of three main parts:
The third point is where we kindly request for feedback.
Explanation: issues are the result of rules being triggered by inspecting the source files.
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 server=##class(%Net.SMTP).%New()
s server.smtpserver="smtp.office365.com"
s server.
(Originally posted by Timur Safin on Intersystems CODE, 3/2/15) This code snippet is a routine that parses options saved in an arguments array. The subroutine "test" runs the code:
Hello Everyone,
I was wondering about the best way to initialize several variables, or several lists of variables.
The following code snippet is a REGEX that validates characters that are not in English, as well as English characters. The class method "test" takes an email address and validates it based on this additional criteria:
(Originally posted by @Eduard Lebedyuk on Intersystems CODE, 6/26/14) This code snippet determines the difference between two ObjectScript lists. The class method "test" runs the code, and its parameters are detailed in the comments:
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?
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!!
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
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 rs.How to Make a Https/SSL Request in Caché ObjectScript ? If possible please provide some working example with some https url.
Is there any COS API to create the database (with designated path) and the namespace ?
Also, the API to attach a given database to a given namespace?
Thanks.
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?
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.
Hello everyone,
what does it mean: <INVALID OREF>zgetFile+8^User.Read.1
(getFile is my ClassMethod and Read.cls is my class)?
I just try to read/load a file.
Im using below code to display page number. But i only display as 1,2..etc. I need to display it as I,II,III..etc...
special="page-number"