Question
· May 12, 2017

Need to good way to convert objects to array in 2014

I was looking at the OrefToArray^%occRun in the %CSP.ErrorLog page in version 2016.  However, we're on version 2014, and that method does not seem to exist yet.  I would love a good way to swizzle out the info in the %request, %session, %response objects for the error log for my own error page, in version 2014.  I don't want to have to go through and get all the properties manually, but I will if I must.  Any other good way  already written?

Thanks,

Laura

Discussion (9)3
Log in or sign up to continue

I could try that... but this is for the user-friendly page, and I don't want that info on it.  I was hoping to log the info in the error trap.

I just tested the error trap, and found that you can, actually, load the details of an object, while still in the error traap ^%ER.  I had no idea:

Error: 7
 
 7. <UNDEFINED> --routine name -- *undef : CSP Error  at  9:41 am.   $I=|TCP|1972|16772   ($X=327  $Y=14056)                                                                                                                       $J=16772  $ZA=24576   $ZB=$c(0)   $ZS=262144 ($S=267019816)
              set x=undef //LLC testing
 
Variable: %request (copying data ... done)
(base stack level = 20)
          %request =     <OBJECT REFERENCE>[1@%CSP.Request]
Show object details? yes
+----------------- general information ---------------
|      oref value: 1
|      class name: %CSP.Request
| reference count: 6

... etc

So, as long as the error trap has that info available, I'm pretty good.  Does that change in 2016?  Why is the %CSP.ErrorLog page in 2016 so careful to save off the request, session, and response objects inthe error log?

Thanks,

Laura

OK, something a little more sophisticated, I've bashed out a class method that should do this for you...
 

ClassMethod ObjectToArray(pObject, Output pArray)
{
    kill pArray
    if '$IsObject(pObject) Quit ""
    set rs=##class(%ResultSet).%New("%DynamicQuery:SQL")
    set sc=rs.Prepare("select Name, RuntimeType, Type from %Dictionary.CompiledProperty where parent=? and NOT Name [ '%'")
    set sc=rs.Execute(pObject.%ClassName(1))
    while rs.Next()
    {
        set property=rs.Data("Name")
        try {
            set pArray(property)=$PROPERTY(pObject,rs.Data("Name"))
        } catch duff { }
    }
    if pObject.%ClassName(1)="%CSP.Request" Merge pArray("CgiEnvs")=pObject.CgiEnvs Merge pArray("Cookies")=pObject.Cookies
}

Just call it for each object you wanted converted to an array, merge that into a global or dump it out to pre tags as before, e.g.

    write "<h2>Request</h2><pre>"
    do ..ObjectToArray(%request,.array)
    zw array
    write "</pre><br><h2>Session</h2><pre>"
    do ..ObjectToArray(%session,.array)
    zw array
    write "</pre><br><h2>Response</h2><pre>"
    do ..ObjectToArray(%response,.array)
    zw array
    write "</pre>"
    Quit $$$OK

And you should get this...

Request

array("AppData")=$lb("",8224,0,"","/csp/healthshare/","Ensemble Management Portal",1,"","",0,1,"","","/csp/healthshare/r","R","","H:\intersystems\CSP\healthshare\r",1,"%Ens_Portal","",2,"",900,2,2,"",3600,0,1,1,"%ISCMgtPortal",1,"","")
array("AppMatch")="/csp/healthshare/r/"
array("Application")="/csp/healthshare/r/"
array("CSPGatewayRequest")=1
array("CgiEnvs","COMSPEC")="E:\WINDOWS\system32\cmd.exe"
array("CgiEnvs","CONTENT_LENGTH")=0
array("CgiEnvs","CONTEXT_DOCUMENT_ROOT")="H:/InterSystems/CSP/"
array("CgiEnvs","CONTEXT_PREFIX")="/csp/"
array("CgiEnvs","CSP_ORIGINAL_FILE")=""
array("CgiEnvs","ComSpec")="E:\WINDOWS\system32\cmd.exe"
array("CgiEnvs","DOCUMENT_ROOT")="H:/InterSystems/CSP"
array("CgiEnvs","GATEWAY_INTERFACE")="CGI/1.1"
array("CgiEnvs","HTTP_ACCEPT")="text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
array("CgiEnvs","HTTP_ACCEPT_ENCODING")="gzip, deflate, sdch, br"
array("CgiEnvs","HTTP_ACCEPT_LANGUAGE")="en-US,en;q=0.8"
array("CgiEnvs","HTTP_CONNECTION")="keep-alive"
array("CgiEnvs","HTTP_COOKIE")="CSPSESSIONID-SP-13333-UP-csp-healthshare-=000000010000nKXcB0rA4r0000Z7RqCT1zYzo6RsrYydAinQ--; CacheBrowserId=zN0TSZMio2VoHmBqhiKm1A--; state-B3B82FCB-2C53-4D41-8B47-CC389A5C7606=SYSEXP%3A1; Username=sean; CSPWSERVERID=fce6d9ad0b3878fbbaef4ad2ad576c9e14c732d1"
array("CgiEnvs","HTTP_HOST")="localhost:13333"
array("CgiEnvs","HTTP_UPGRADE_INSECURE_REQUESTS")=1
array("CgiEnvs","HTTP_USER_AGENT")="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36"
array("CgiEnvs","PATH")="E:\ProgramData\Oracle\Java\javapath;E:\Program Files (x86)\Intel\iCLS Client\;E:\Program Files\Intel\iCLS Client\;E:\WINDOWS\system32;E:\WINDOWS;E:\WINDOWS\System32\Wbem;E:\WINDOWS\System32\WindowsPowerShell\v1.0\;E:\Program Files\Intel\Intel(R) Management Engine Components\DAL;E:\Program Files\Intel\Intel(R) Management Engine Components\IPT;E:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;E:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;E:\Program Files (x86)\QuickTime\QTSystem\;E:\Program Files (x86)\Git\cmd;E:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;E:\WINDOWS\system32;E:\WINDOWS;E:\WINDOWS\System32\Wbem;E:\WINDOWS\System32\WindowsPowerShell\v1.0\;E:\Program Files (x86)\Pandoc\;E:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;E:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\;E:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\;E:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio\;E:\Program Files (x86)\Skype\Phone\;E:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;E:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;E:\Program Files\Microsoft SQL Server\120\Tools\Binn\;E:\Program Files\Microsoft SQL Server\120\DTS\Binn\;E:\Program Files\nodejs\;E:\WINDOWS\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps"
array("CgiEnvs","PATHEXT")=".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
array("CgiEnvs","PATH_TRANSLATED")="H:/InterSystems/CSP/csp/healthshare/r/Foo.Session.cls"
array("CgiEnvs","QUERY_STRING")=""
array("CgiEnvs","REMOTE_ADDR")="::1"
array("CgiEnvs","REMOTE_PORT")=53822
array("CgiEnvs","REQUEST_METHOD")="GET"
array("CgiEnvs","REQUEST_SCHEME")="http"
array("CgiEnvs","REQUEST_URI")="/csp/healthshare/r/Foo.Session.cls"
array("CgiEnvs","SCRIPT_FILENAME")="H:/InterSystems/CSP/healthshare/r/Foo.Session.cls"
array("CgiEnvs","SCRIPT_NAME")="/csp/healthshare/r/Foo.Session.cls"
array("CgiEnvs","SERVER_ADDR")="::1"
array("CgiEnvs","SERVER_ADMIN")="[no address given]"
array("CgiEnvs","SERVER_NAME")="localhost"
array("CgiEnvs","SERVER_PORT")=13333
array("CgiEnvs","SERVER_PORT_SECURE")=0
array("CgiEnvs","SERVER_PROTOCOL")="HTTP/1.1"
array("CgiEnvs","SERVER_SIGNATURE")=""
array("CgiEnvs","SERVER_SOFTWARE")="Apache Cache_Server_Pages-Apache_Module/2014.1.1.702.0-1401.1419b"
array("CgiEnvs","SystemRoot")="E:\WINDOWS"
array("CgiEnvs","WINDIR")="E:\WINDOWS"
array("CgiEnvs","windir")="E:\WINDOWS"
array("CharSet")="utf-8"
array("Content")=""
array("ContentType")=""
array("Cookies","CSPWSERVERID",1)="fce6d9ad0b3878fbbaef4ad2ad576c9e14c732d1"
array("Cookies","CacheBrowserId",1)="zN0TSZMio2VoHmBqhiKm1A--"
array("Cookies","Username",1)="sean"
array("Cookies","state-B3B82FCB-2C53-4D41-8B47-CC389A5C7606",1)="SYSEXP%3A1"
array("GatewayApplication")="/csp"
array("GatewayBuild")="661.1401.1419b"
array("GatewayConnectionName")="LOCAL"
array("GatewayError")=""
array("GatewayFunctions")=7
array("GatewayInstanceName")="alien:13333"
array("GatewayNewId")=0
array("GatewaySessionCookie")="CSPSESSIONID-SP-13333-UP-csp-healthshare-"
array("GatewayTimeout")=60
array("Method")="GET"
array("PageName")="Foo.Session.cls"
array("Protocol")="HTTP/1.1"
array("RequestId")="2E98"
array("Secure")=0
array("URL")="/csp/healthshare/r/Foo.Session.cls"
array("URLPrefix")=""
array("UserAgent")="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36"

Session

array("AppTimeout")=900
array("Application")="/csp/healthshare/r/"
array("ApplicationLicenses")=""
array("BrowserName")="Safari"
array("BrowserPlatform")="Windows"
array("BrowserVersion")=537.36
array("ByIdGroups")=$lb("%iscmgtportal:zN0TSZMio2VoHmBqhiKm1A--")
array("CSPSessionCookie")="000000010000nKXcB0rA4r0000Z7RqCT1zYzo6RsrYydAinQ--"
array("CookiePath")="/csp/healthshare/"
array("CreateTime")="2017-05-12 13:51:19"
array("Debug")=0
array("EndSession")=0
array("ErrorPage")=""
array("EventClass")=""
array("GetNewId")=0
array("GroupId")="%iscmgtportal:zN0TSZMio2VoHmBqhiKm1A--"
array("HttpAuthorization")=""
array("KeepAlive")=1
array("Key")="è$½Wò"_$c(31)_"qÎ3ñ3fy"_$c(132,30,3)
array("Language")="en-us"
array("LastModified")="2017-05-12 14:06:57"
array("LicenseId")="sean@127.0.0.1"
array("LogoutCleanup")=0
array("MessageNumber")=2
array("Namespace")="R"
array("NewSession")=0
array("OldTimeout")=5565507717
array("Preserve")=0
array("ProcessId")=""
array("RunNamespace")=""
array("SOAPRequestCount")=0
array("SecureSessionCookie")=0
array("SecurityContext")=$lb("sean","%All","%All",32,-559038737)
array("SessionId")="nKXcB0rA4r"
array("StickyLogin")=""
array("UseSessionCookie")=2
array("UserAgent")="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36"
array("Username")="sean"
array("nosave")=0

Response

array("CharSet")="utf-8"
array("ContentLength")=""
array("ContentType")="text/html"
array("CookiePath")="/csp/healthshare/"
array("Domain")=""
array("Expires")="Thu, 29 Oct 1998 17:04:19 GMT"
array("GzipOutput")=""
array("HTTPVersion")=""
array("HeaderCharSet")=""
array("InProgress")=1
array("Language")="en-us"
array("NoCharSetConvert")=0
array("OutputSessionToken")=1
array("Redirect")=""
array("ServerSideRedirect")=""
array("Status")="200 OK"
array("Timeout")=""
array("TraceDump")=0
array("UseASPredirect")=0
array("UseHttpOnly")=1
array("VaryByParam")=""