How to get application errors (^ERRORS) using a command
InterSystems FAQ rubric
Use the ErrorList query of the SYS.ApplicationError class.
- Note 1: Runs in the %SYS namespace.
- Note 2: This is a non-stored utility, so we use the %ResultSet class rather than %SQL.Statement.
An example of command execution is as follows.
USER>set$namespace="%SYS" //equal to zn "%SYS"%SYS>set rset=##class(%ResultSet).%New()
%SYS>set rset.ClassName="SYS.ApplicationError"%SYS>set rset.QueryName="ErrorList"// The first argument of the query is the namespace name, the second argument is the date (in MM/DD/YYYY format).%SYS>do rset.Execute("USER","08/17/2020")
// To display the results on the screen, execute the %Display() method.%SYS>do rset.%Display()
Error # Error message Time Process DisplayPID Username Code line
1 <DIVIDE> 02:43:1025362536 irisowner
1 Rows(s) Affected
%SYS>do rset.Close()The following shows how to get column values of a SELECT while navigating through rows.
To move to a row, use the Next() method (which returns 1 if the row exists).
To get a column, use Get("column name"). For details on column names, please refer to the description of the ErrorList query in the class documentation.
About column names of ErrorList queries.
%SYS>do rset.Execute("USER","08/17/2020")
%SYS>while rset.Next() { write rset.Get("Error #"),"-",rset.Get("Error message"),"-",rset.Get("Time"),"-",rset.Get("Code line"),!}
1-<DIVIDE>-02:43:10-For terminal viewing, you can also use the ^%ER routine.
Execute the following while in the namespace you want to reference (the example is executed in the USER namespace).
The green bold underlined text indicates the input area.
USER>do ^%ER
For Date: ?L
Thu 09/17/2020 (T) 2 Errors
Mon 09/07/2020 (T-10) 3 Errors
Mon 08/31/2020 (T-17) 1 Error
Mon 08/24/2020 (T-24) 1 Error
For Date: 09/17/2020 17 Sep 2020 2 Errors
Error: ?L
1. " *a" at 9:05 am. $I=|TRM|:|13484 ($X=0 $Y=15)
$J=13484 $ZA=0 $ZB=$c(13) $ZS=262144 ($S=268271680)
2. "^%ETN" at 9:05 am. $I=|TRM|:|13484 ($X=0 $Y=17)
$J=13484 $ZA=0 $ZB=$c(13) $ZS=262144 ($S=268263368)
%ETN ;%STACK-related error log
Error: 1
1. " *a" at 9:05 am. $I=|TRM|:|13484 ($X=0 $Y=15)
$J=13484 $ZA=0 $ZB=$c(13) $ZS=262144 ($S=268271680)
Variable:
Error:
For Date:
USER>For Date: specify the date when the error occurred in the mm/dd/yyyy format.
For Error: specify the error number.
When you are finished viewing, press Enter to exit.
Comments
Hello Mihoko,
Really useful class to get the errors. I did some slight modification in that code to use it
ClassMethod GetErrorLogs(pDate = {$H})
{
Set oldNamespace = $NamespaceNew$NamespaceSet$Namespace= "%SYS"Set tResult = ##class(SYS.ApplicationError).ErrorListFunc(oldNamespace,$ZDate(pDate))
Do tResult.%Display()
}
or over SQL using OEX package SQL-for-ERRORS-Global