go to post Timothy Leavitt · Nov 4, 2016 There isn't a built-in method that does exactly what you're looking for, that I know of. Here's a simple example of how to do it, though: Class DC.Demo.ArrayUtils { ClassMethod ArrayObjectToArray(pSource As %Collection.AbstractArray, Output pTarget) { Kill pTarget Set tKey = "" For { Set tItem = pSource.GetNext(.tKey) Quit:tKey="" Set pTarget(tKey) = tItem } } ClassMethod ArrayToArrayObject(ByRef pSource, pTarget As %Collection.AbstractArray) { // Could initialize pTarget here and return it Output, or return it normally. // This is just a bit more general because it'll work with any array collection type. Do pTarget.Clear() Set tKey = "" For { Set tKey = $Order(pSource(tKey),1,tItem) Quit:tKey="" Do pTarget.SetAt(tItem,tKey) } } } Usage: USER>s aodt=##class(%ArrayOfDataTypes).%New() USER>w aodt.SetAt("lcavanaugh","username") 1 USER>w aodt.SetAt("organization","coolcompany") 1 USER>zw aodt aodt=<OBJECT REFERENCE>[1@%Library.ArrayOfDataTypes] +----------------- general information --------------- | oref value: 1 | class name: %Library.ArrayOfDataTypes | reference count: 2 +----------------- attribute values ------------------ |Data("coolcompany") = "organization" | Data("username") = "lcavanaugh" | ElementType = "%String" +----------------------------------------------------- USER>do ##class(DC.Demo.ArrayUtils).ArrayObjectToArray(aodt,.array) USER>zw array array("coolcompany")="organization" array("username")="lcavanaugh" USER>s newaodt = ##class(%Library.ArrayOfDataTypes).%New() USER>do ##class(DC.Demo.ArrayUtils).ArrayToArrayObject(.array,newaodt) USER>zw newaodt newaodt=<OBJECT REFERENCE>[2@%Library.ArrayOfDataTypes] +----------------- general information --------------- | oref value: 2 | class name: %Library.ArrayOfDataTypes | reference count: 2 +----------------- attribute values ------------------ |Data("coolcompany") = "organization" | Data("username") = "lcavanaugh" | ElementType = "%String" +----------------------------------------------------- If you really wanted to make BuildValueArray work: USER>d aodt.%SerializeObject(.serial) USER>d aodt.BuildValueArray($lg(serial),.anotherarray) USER>zw anotherarray anotherarray("coolcompany")="organization" anotherarray("username")="lcavanaugh" The utility method approach would probably at least be clearer.
go to post Timothy Leavitt · Nov 4, 2016 Here's one lazy option: USER>w $System.SQL.CEILING(.1) 1 USER>w $System.SQL.CEILING(1.2) 2 USER>w $System.SQL.CEILING(1.7) 2 If you look at the implementation of that method in %SYSTEM.SQL, you'll see: $s('$isvalidnum(val):"",+val[".":+$p(val,".")+(val>0),1:+val) So that's another option (although messier).
go to post Timothy Leavitt · Nov 2, 2016 Stepping back a bit: What endpoint are you using? From Terminal, I see different certificates for googleapis.com and www.googleapis.com: USER>set old = $io set dev = "|TCP|443" open dev:("googleapis.com":443:/TLS="Demo") use dev w 123,! use dev s cer = $System.Security.Users.SSLGetPeerCertificate() use old w $System.Encryption.X509GetField(cer,"Subject"),!,$System.Encryption.X509GetField(cer,"Extension:subjectAltName") CN=www.google.com,O=Google Inc,L=Mountain View,ST=California,C=US DNS:www.google.com USER>close dev set old = $io set dev = "|TCP|443" open dev:("www.googleapis.com":443:/TLS="Demo") use dev w 123,! use dev s cer = $System.Security.Users.SSLGetPeerCertificate() use old w $System.Encryption.X509GetField(cer,"Subject"),!,$System.Encryption.X509GetField(cer,"Extension:subjectAltName") CN=*.googleapis.com,O=Google Inc,L=Mountain View,ST=California,C=US DNS:*.googleapis.com, DNS:*.clients6.google.com, DNS:*.cloudendpointsapis.com, DNS:cloudendpointsapis.com, DNS:googleapis.com However, in my browser, if I navigate to https://googleapis.com, I see the googleapis.com certificate (and a 404 error). This difference in behavior might have something to do with Caché's lack of support for Server Name Indication (SNI). Regardless, what happens if you change the endpoint to www.googleapis.com rather than googleapis.com?
go to post Timothy Leavitt · Nov 2, 2016 LOGIN^%ZSTART could do the trick. See the documentation. For example, put this in %ZSTART.mac: Quit LOGIN Do ^%CD Quit Then, when you log in to terminal, you'll get: Username: tleavitt Password: *** Namespace: ? '?' for help. '@' (at-sign) to edit the default, the last namespace name attempted. Edit the line just as if it were a line of code. <RETURN> will leave you in the current namespace. Here are the defined namespaces: %SYS ... Namespace: USER You're in namespace USER Default directory is c:\intersystems\ensemble2\mgr\user\ USER> If you wanted to make this a per-user setting, it'd take a bit more work, but would certainly be possible.
go to post Timothy Leavitt · Nov 2, 2016 I think this is the expected/designed behavior - when you log in as that user, that routine runs rather than giving you the typical terminal prompt. When the routine quits/ends, so does the terminal session.
go to post Timothy Leavitt · Oct 26, 2016 Another (possibly better) option, if your users are squeamish about entering their passwords in plain text, would be to create a simple UI page (CSP or Zen) for commits and launch it with Action = 2.
go to post Timothy Leavitt · Oct 26, 2016 Assuming you're doing this using the Studio extension framework, the class reference for %Studio.Extension.Base has really helpful documentation.I think the pattern you want is:In UserAction, return Action = 7 for your menu item(s):7 - Display a dialog with a textbox and Yes/No/Cancel buttons. The text for this dialog is provided by the 'Target' return argument. The initial text for the textbox is provided by the 'Msg' return argumentThe user can enter a password in this dialog. Then, in AfterUserAction, you can handle the user's response.
go to post Timothy Leavitt · Oct 20, 2016 The best tool I've seen for tracking unit test coverage in Caché ObjectScript is https://github.com/litesolutions/cache-utcov - maybe you'd already found that from some old Developer Community posts. However, it's gone stale, it's not really mature/complete, and it doesn't have a solution for the problem you've described. There are further complications because %Monitor.System.LineByLine looks at the generated (.int) code, which contains code that isn't in the class definition (because it's generated) and may not contain code that is in the class (for example, a classmethod that returns a constant). It also looks at code line-by-line, and there may be multiple statements on a line; tracing with ZBREAK instead could be a solution for this.It's worth noting that #; comments don't appear in .int code - so, if only this type of comment is used, you could accurately measure the percentage of code coverage for a method/classmethod as the percentage of code coverage of the generated .int code corresponding to the method/classmethod. Otherwise, you're stuck parsing the code (which, if you're just trying to detect comments, wouldn't be too bad) to detect lines that contain comments and omit them from consideration when determining code coverage percentage.
go to post Timothy Leavitt · Oct 18, 2016 Here's one option: <column header="Total Phones" colName="TotalPhones" colExpression="(select count(*) from ZenTutorial.PhoneNumber where Contact=ZenTutorial.Contact.ID)" width="9%" /> The colExpression property allows you to specify a more complex expression to get the value for the column.
go to post Timothy Leavitt · Sep 21, 2016 Another great alternative REST client is Postman - I used Advanced REST Client for a while before switching to it. I think the motivation for switching was better HTTP redirect handling in Postman.
go to post Timothy Leavitt · Sep 20, 2016 System default settings are likely the right tool for the job. Settings can be controlled separately from the production definition.
go to post Timothy Leavitt · Sep 20, 2016 I've observed the same issue (garbage output) on a few occasions when there is output (i.e., write statements) before HTTP headers are written. The garbage output might be a CSP Gateway issue, but it is wrong to write prior to headers anyway. Other than redesigning the class entirely, one thing to try might be outputting headers at the beginning of OnHTTPHeader: Set tStatus = %response.WriteHTTPHeader(.OutputBody) It looks like this doesn't happen automatically if OnHTTPHeader is overridden. Note that %response.WriteHTTPHeader(.OutputBody) will indicate "don't call OnPage" (OutputBody = 0) if there's a redirect or server-side redirect. It's worth considering how your custom OnHTTPHeader behavior should interact with redirects.
go to post Timothy Leavitt · Sep 1, 2016 You can change namespace in Caché ObjectScript with: Set $Namespace = "SomeOtherNamespace" In methods that do that, it's typically good to start out with: New $Namespace To ensure that the namespace switches back once it's out of that context. Of course, you need to be sure that any code you call is available in the new namespace, and it would be good to think carefully about security implications. The management portal uses the $NAMESPACE parameter in the URL along with %request.Context to add it to other URLs so you stay in the same namespace across pages.
go to post Timothy Leavitt · Aug 24, 2016 Here's one option: ##class(%SYS.System).InstanceGUID() See the class reference.
go to post Timothy Leavitt · Aug 22, 2016 You can pass a stream to $fromJSON instead of a string: USER>set tStream = ##class(%Stream.TmpCharacter).%New() USER>d tStream.Write("{""a"":2}") USER>s obj = {}.$fromJSON(tStream) USER>w obj.a 2 In your case: Set RequestObj = ##class(%Object).$fromJSON(%request.Content) This is much easier than reading the stream into a string first, and avoids <MAXLENTH> issues.
go to post Timothy Leavitt · Aug 16, 2016 If you're talking about storing dynamic data along with the session, see the documentation on %session.Data. This is just a multidimensional property - so you can do something like: Set %session.Data("hello","world")=15 And then reference that data in a request later in the same session. For a more advanced approach - for example, if there's a large amount of data related to the session - you could use one or more tables instead, and clear data when appropriate by implementing OnEndSession in a subclass of %CSP.SessionEvents and configuring that class as the session events class for your web application (in the web application's security settings).
go to post Timothy Leavitt · Aug 12, 2016 One important note on I/O redirection, from the documentation:When a process performs I/O redirection, this redirection is performed using the user’s login $ROLES value, not the current $ROLES value.In other words, if the I/O redirection is happening in a CSP application or privileged routine application context, in which matching or application roles are added that grant permissions on resources protecting assets the I/O functions need, you might get an unexpected <PROTECT> error, with roles seeming to disappear in wstr()/etc.For the simple case of outputting to a string (as in this example) this is no big deal, but there may be issues with some types of streams, for example, if the stream implementation tries to set/kill globals. (This caught me by surprise the other day.)
go to post Timothy Leavitt · Aug 11, 2016 As written, the code in your post should work fine.If the parameter '1' is actually a COS variable name, then the "undefined" would be expected (since the variable with that name is not defined in JavaScript), and you could use something like:&js<zenPage.doReturn(#(..QuoteJS(myVariableName))#);>