#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 Evgeny Shvarov · May 26, 2017

Hi!

I'm saving object instance using RestForms.

RESTFormsUI calls %Save() for me, which is great. But I want to set the property CreationDate with the current date for every new record being inserted.

So  object callback implementation seems as a reasonable option. I did the following:

Method %OnBeforeSave(insert as %Boolean) As %Status [ Private, ServerOnly = 1 ] 
{

 if insert s ..CreationDate=$H

 q $$$OK

}

And it works fine.

But Documentation says I'd better use %OnAddToSaveSet()

What are you using for the callbacks in similar cases?

15
0 1030
Article Vitaliy Serdtsev · May 20, 2017 10m read

This is a translation of the following article. Thanks @Evgeny Shvarov  for the help in translation.

Let's assume that you wrote a program that shows "Hello World!", for example:

  write "Hello, World!"

The program works and everyone is happy.

With time, however, your program becomes more complex, gets more features and you eventually need to show the same string in different languages. Moreover you don't know the number and names of these languages.

The spoiler below contains a description of how the task of multi-language localization is solved in Caché.

1
1 1176
Question P Patz · May 12, 2017

Looking for a way in which I could possibly pass a flag through a property when performing an Insert statement, on a mapped class.

insert into my.class (serialNumber, modelNumber, myFlag) value ('testSerial', 'testModel', 0)
    myFlag is not stored in the DB.

The mapped class then calls a legacy routine (MAC) via CodeMode = 'objectgenerator', (Insert method within the 'objectgenerator')

Within the legacy routine, I am setting an index... but I don't always want to set it (multiple inserts, and I will only set the index on the LAST insert)

4
0 328
Question Alexander Grishkan · May 9, 2017

What is a correct way to pass parameters to the  %CONTAINS in embedded SQL statement when searching thru %Text property?

s sp="child,health"

&SQL(

DECLARE c1 CURSOR FOR

SELECT ID INTO :id FROM ICD WHERE Name %CONTAINS (:sp)

...

is not the same as executing the following in the SQL Manager

SELECT ID FROM ICD WHERE Name %CONTAINS ('child','health')

4
0 502
Question Arto Alatalo · Apr 11, 2017

I have classes A and B, B derived from A, A has method Abc.

From INT of class B I see that compiler copies implementation of Abc to class B, so that Abc exists both in A and B.

As result, when B invokes Abs, B.Abs() is executed instead of A.Abs(). In result debuger is not able to step into Abs and breakpoints in A.Abs never hit.

Why this happens and how can I avoid this?

Update:

OK, now I know the reason: compiler makes the copy if Abc has this line:

cn=##Expression($$$quote(%classname))

21
0 497
Question Scott Roth · Apr 11, 2017

With help from others here I had developed some code to take a Base64 PDF within a OBX.5 and save it locally to the file structure on the server.

I had to make a change to the code to return me a String so I can pass the Path back into Ensemble to use it in the message. When I made this change I am getting " ERROR #5034: Invalid status code structure ("/ensemble/data/transfer/AncillaryPDF/TMSAUDIO/Apr-11-1/980512729TMSAUDIO1046784936436537800.pdf")"

Here is the code...

3
0 1303
Question Gordon Hodgkinson · Apr 9, 2017

Hi All,

Am attempting to run sample unit tests as per

Caché %UnitTest Tutorial
Example: Executing a Test Using Set-Up and Tear Down Methods
 

 and getting an ERROR #5007:

The Terminal detail is as follows:

SAMPLES>Set ^UnitTestRoot="C:\UnitTests"                                        
SAMPLES>write ^UnitTestRoot
C:\UnitTests
SAMPLES>do ##class(%UnitTest.Manager).RunTest("MyTests")
 
ERROR #5007: Directory name '/usr/cachesys/mgr/samples/C:/UnitTests/MyTests/' is invalid
SAMPLES>

2
0 546
Question Massimo Sebastiani · Mar 30, 2017

Hello, we have a few hundreds of triggers to port from Oracle to Cachè for a migration project, and many of them have to change (for example, normalize a value, null it, etc) the value which is being inserted.

The documentation says "You cannot set {fieldname*N} in trigger code." , so we're unlucky.

Is there a good workaround for this ?

SqlComputeOnChange doesn't seem the best way, but I'm not totally sure: for example normalization and validation could have a better place somewhere else than a trigger.

2
0 435
Question Jorge de la Garza · Mar 10, 2017

What are the differences between a process private global and a percent variable?  Basically I have some code running in an Ensemble operation that processes requests, and it needs access to pieces of data that are scattered throughout XData blocks in various classes.  Rather than opening the XData object and deserializing the XML on each request, I opted to cache this data in a percent variable, something like:

set %MyVar(sub1,sub2) = myValue

10
0 1958
Question John Flippance · Mar 29, 2017

Hello,

We are working on creating a metadata file to accompany PDF documents produced by one of our third party systems for ingestion into our DMS.  One of the pieces of data that the metadata file must contain is the number of pages of the PDF document.

In Cache ObjectScript does anybody know if there is currently a way of counting the number of pages within a file (specifically a PDF) without invoking a non-Caché ObjectScript program/function from within Caché ObjectScript?

3
0 2323
Article Andrei Luiz Nenevê · Mar 29, 2017 1m read

Hi everyone,

I've created an Identicon Generator inspired on Fabio GonçalvesCaptcha Validator.

This sample can be used to create Identicons for users of app for example, it can be useful to use in Zen Mojo applications, generating an identifier image based on name of the user by example, but it can be used in others kind of applications too(Zen, CSP etc)

Examples:

First one:

Will generate this:

 

And this:

Will generate this:

See my Github project: https://github.com/AndreiLN/Ikon

Best regards,

Andrei L. Nenevê

0
0 579
Article Sean Connelly · Mar 28, 2017 2m read

Inspired by the article "Declarative development in Caché" that's still trending  on the dev com. The OP explored a functional style of iterating over a collection. A comment today suggested "Caché would need syntax support for anonymous functions".

With Macros you can kind of get anonymous like syntax using dot notation.

This is not production code, but it does work. First the macros...

15
0 755