#ObjectScript

0 Followers · 1.5K 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 Eduard Lebedyuk · Mar 23, 2017

Let's say I have two classes: A and B. They share no common parent except %SystemBase. But these classes have some properties with the same name (type may be the same or not):

Class A {

Property data As C;

Property data2;

}
Class B {

Property data As D;

Property data3;

}

I need to automatically convert  object of class A into object of class B. I'm planing to write a class generator that generates a separate class that converts A to B.  It would work like this:

1. Query %Dictionary to get list of properties:

  • With the same names
  • With both properties being of datatype or object type
4
0 472
Question Scott Beeson · Feb 5, 2016
selecttype ; select gateway or ihe
     read "Deployment Type? (G)ateway or (I)HE: ", dtype
dataentry ; first data entry routine
     if (dtype="G") {
          set dtypeFull = "Gateway"
     elseif (dtype="I") {
          set dtypeFull = "IHE"
     else {
          write !,"Invalid Choice",!
          goto selecttype
     }
     Write !, "Starting ", dtypeFull," deployment..."

This was what I first wrote.  Here is the test, first putting in an invalid value:

Deployment Type? (G)ateway or (I)HE: F
Invalid Choice
Deployment Type? (G)ateway or (I)HE: G
Starting Gateway deployment...

 

19
0 754
Question Thomas Chericka · Dec 15, 2016

Hi, I've organized my repository using TortoiseSVN. I was careful to use only svn commands while creating my file structure. Now all Subversion commands are working at the command line but not from within my IDE (Cache Studio). Basically I'm trying to write a plug-in for my IDE to use Subversion from within the Studio. Trying to integrate Subversion into my IDE, something like Subclipse, but for Cache Studio.  The error occurred after reorganizing my code into directories. For example at the command-line, svn info and svn status and all other commands work perfectly.  All Subversion commands

8
0 1548
Question Alexander Grishkan · Mar 8, 2017

I am sending an HTTP request to cache class:

s rObj=##class(%Net.HttpRequest).%New()s rObj.Server="www.xyz.com"s rObj.Https=1s rObj.SSLConfiguration="xyz"s rObj.ContentType="application/json"d rObj.EntityBody.Write("payload in json format")s sc=rObj.Post("/csp/ns/xyz.cls")

The request gets to the OnPreHTTP class method 

Class xyz Extends %CSP.Page [ ProcedureBlock ]
{

ClassMethod OnPreHTTP() As %Boolean
{
    q 1

}

}

The question is how to retrieve the request payload in the OnPreHTTP method.

4
0 1242
Question Ben Spead · Mar 7, 2017

I am trying to write some code that takes in a string and does a serverside transformation of it to find embedded URLs and replace it with clickable links.   I found the following regex for Javascript which is rated highly on StackOverflow;

    replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
    replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>');

And I tried to do the following in Caché ObjectScript but it's not working:

3
0 640
Question Evgeny Shvarov · Feb 25, 2017

Hi!

Consider I have a class Package.Data with Property UniqueStringValue as %String.

I introduced the Index for this property:

 Index ValueIndex on UniqueStringValue [Unique];

It works well.  But if I try to check if there is an object with the certain value in code like this:

if ##class(Package.Data).ValueIndexExists(value)  

this expression fails, if value="value", even if there is an instance with instance.UniqueStingValue="Value"

How can I set the index to prevent saving case sensitive values in this class?

6
0 643
Question Mack Altman · Feb 23, 2017

While I can see the benefits that $ZSTORAGE could have if used properly, I have not seen it used in the environments I have worked in. I was wondering if there are any developers that promote its usage.

If used properly, I would imagine it could be highly effective in maximizing free memory since some processes will never go over X amount, while others may very well need much more.

2
0 424
Question Alexander Brown · Feb 6, 2017

If I were trying to access an index of a global variable, what time complexity would this operation have? My understanding of languages like Java/C++ is that arrays are stored as blocks of memory so that x[15] would have a lookup time complexity of O(1) because it just goes to (address of the array + 15) and retrieves the value stored there.

How does this work in Cache where the index of a variable isn't necessarily an integer value? If I were to have a variable like the following:

x("Adam") = "Red"

x("George") = "Blue"

x("Bryan") = "Green"

etc...

5
0 589
Question Mack Altman · Jan 25, 2017

I am in the planning stages of making things more uniform in our routines and I would like to know what the easiest way would be to include an .inc at the beginning of each .mac routine. Has anyone written something that would open all routines and place something into the first row while leaving the rest of the routine unchanged? Thanks for any guidance you all may provide.

3
0 423
Article Steve Wilson · Feb 3, 2017 3m read

Points to remember before you start: 

  1. It is not possible in a COS (Caché Object Script) job/process context to have multiple Named Pipes. It is a one Named Pipe per job/process limited line of communication. 
  1. Named Pipes, in Caché, like most pipes on most operating systems are Unidirectional. That means you open them for either Read or Write, but not both. 
0
0 856
Question Murillo Braga · Jan 30, 2017

Hello guys,

I've got this piece of code which runs the method "WebMethod", that belongs to %SOAP.WebBase.cls.

It grabs the outcome from an internal webservice we have and after that, it writes into a file.

The thing is, when I browse the file contents, I realize that in the place where a special character should be, I see a question mark.

By querying the same webservice from a special soap tool called "SoapSonar" (I've been using this for years), the outcome shows up this special character (shows it properly).

16
0 5323
Article Timur Safin · Jan 16, 2017 15m read

Have you ever thought what could be a reason why some development environment (database, language) would eventually become popular? What part of this popularity could be explain as language quality? What by new and idioms approaches introduced by early language adopters? What is due to healthy ecosystem collaboration? What is due to some marketing genius?

2
2 1422
Article Kyle Baxter · Jan 12, 2017 3m read

So I know it's been a while, and I hate to let my adoring fans down... just not enough to actually start writing again.  But the wait is over and I'm back!  Now bask in my beautiful ginger words!

For this series, I am going to look at some common problems we see in the WRC and discuss some common solutions.  Of course, even if you find a solution here, you are always welcome to call in and expression you gratitude, or just hear my voice!

This week's common problem: "My query returns no data."

1
0 507
Question Evgeny Shvarov · Dec 18, 2016

Hi, community!

Consider you need to exclude substring(s) from a string.

I did it with the following snippet:

/// excludes all the substrings from the string
ClassMethod ExcludeSubstring(substr,str as %String) As %String

{

 while ($L(str,substr)>1) {

 set str=$Piece(str,substr)_$Piece(str,substr,2,*)

            }

 quit str

}

So, for example:

USER> set str=”ExcludemeGoodstringExcludemeExcludemeGoodstring” w ##class(User.Utils).ExcludeSubstring(“Excludeme”,str)

GoodstringGoodstring

Is this the optimal approach or I reinvented the wheel?

2
0 476
Question Josh Tennefoss · Dec 9, 2016

Is there any way that I can check the native type of an object script variable? (similar to the typeof check in javascript)

I see that the DynamicArray class uses the type of the variable for its output, I would like to do something similar when I receive a value as an argument to my method.

USER>s var1 = 123  //No quotes, number type
 
USER>s var2 = "123" //quotes, string type
 

//DynamicArray can tell the difference
USER>s arr = []
 
USER>d arr.%Push(var1)
 
USER>d arr.%Push(var2)
 
USER>w arr.%ToJSON()
[123,"123"] //first value is output without quotes, second value is quoted

3
0 684
Question Josh Tennefoss · Dec 9, 2016

How can I prevent large number truncation when using the DynamicObject and DynamicArray classes to create JSON in objectscript and then parsing the result in javascript. Are there any global settings that configure the output when using these classes?

I am looking at converting to the new DynamicObject and DynamicArray classes to build JSON. Our current (homegrown) JSON library forces string representation of numbers too long because of errors we were seeing with long numbers being truncated on the client, I am hoping to accomplish the same with the new classes.

2
0 1356
Question Scott Roth · Dec 8, 2016

Using the following...

//Get PDF stream object previously saved
   Set pdfStreamContainer = ##Class(Ens.StreamContainer).%OpenId(context.StreamContainerID)
   Try {
     Set pdfStreamObj = pdfStreamContainer.StreamGet()
   }
   Catch {
      $$$TRACE("Error opening stream object ID = "_context.StreamContainerID)
      Quit
   }

Would it be possible to search the pdfStreamObj for certain values like a Medical Record, or Patient Name?

Thanks

Scott

1
0 1125
Question Thomas Chericka · Dec 8, 2016

Hi,

Thanks for your time.

Plain $ZF(-1) and $ZF(-2) calls from Cache Studio or Terminal have stopped launching the OS shell from Win10.

cmd (Windows Command Prompt) should be launched.

Configuration:

Windows 10 Anniversary Update, Ensemble 2016.2.0.585.0 Developer Edition x64

Is this common? I have enabled both %Developer role and a Cache CallOut privilege for all users that operate in this scenario.

In Terminal, W $ZF(-1) prints -1, W $ZF(-2) prints -1

In Studio, W $ZF(-1) hangs the IDE, W $ZF(-2) prints 0

In all four cases, cmd (Windows Command Prompt) is not launched!

Any ideas, anybody?

2
0 1367
Question Mack Altman · Dec 2, 2016

We don't often use SQL within our org, which is mostly due to the performance issue we experience due to the quantity of data we are reviewing.

Aside from the standard performance measures for non-Caché databases, are there any recommended approaches when querying large tables?

The table would have roughly 50M records, but there are not a finite amount of sub-nodes.

7
0 1064
Question Scott Roth · Nov 22, 2016

I am trying to write some code to check to see if a directory exists before creating a new directory.

When I do the following I am not getting a response, but the directory exists..

do ##class(%File).DirectoryExists("/ensemble/")

am I missing something?

5
0 997