How to write an ObjectScript Task to export Audit log to a directory and under which namespace?
Hi All,
Can you please guide me on how to programmatically write objectscript task to export audit log to a directory and what type of task should I set it to.
I want to achieve the same behaviour on the code as seen below
Product version: IRIS 2020.2
$ZV: HealthShare 2020.2 [HealthShare Modules: Active Analytics:20.0.8620 + Core:20.0.8620 + Patient Index:20.0.8620] - IRIS for UNIX (Red Hat Enterprise Linux for x86-64) 2020.1 (Build 217_1_20418U) Tue Nov 17 2020 15:48:44 EST
Hi Ephraim -- I had success creating a task with these settings:
That last provided argument is the end date/time; you may want to adjust to your needs.
Thanks Michael,
It worked, so is there a way to put date range, say for example exporting records from 2022-03-01 to 2022-04-11?
Hey Ephraim.
You will see from looking at the classmethod being called that there is a start date parameter which was left blank by Michael so that it will export everything up to the end date.
In your case, you could do the following to fulfil your example:
However this will only be useful to your specific date range, which is where Michaels use of $ZDT and $H come into play.
If you wanted to execute the task and have it return the last 30 days, you could do this:
Hi guys,
Is there a way to specify every month without saying last 30 days since other months have 30 days and February has 28 days? There is a requirement to schedule this task to run every month, I will appreciate it if I get some guidance on that
Hey Ephraim.
I have thrown together a task which should do what you need. The code is a bit verbose and could be cut down a touch, but hopefully it's human readable enough for you to pick out what its doing.
Effectively, it takes the current date to then grab a date from last month, and then gets the first and last date of that month to then use in the audit method.
Class Demo.Tasks.MonthlyAudit Extends %SYS.Task.Definition { Method OnTask() As %Status { Set tSC = $$$OK //Get Current Date Set CurentDatetime = $ZDATETIME($HOROLOG,3) //The report needs to be for last month, so get a date from last month based on todays date Set LastMonth = $SYSTEM.SQL.DATEADD("MM",-1,CurentDatetime) //Get last Day of last month As Horolog Set LastDayHoro = $SYSTEM.SQL.LASTDAY(LastMonth) //Convert Horolog into a Date Set LastMonthEnd = $ZDATETIME(LastDayHoro,3) //Get First Day of Last Month Set LastMonthStart = $SYSTEM.SQL.DATEPART("YYYY",LastMonthEnd)_"-"_$SYSTEM.SQL.DATEPART("MM",LastMonthEnd)_"-01" //Switch to the %SYS Namespace ZNspace "%SYS" Set tSC = ##class(%SYS.Audit).Export("AuditExport.xml",,,LastMonthStart_" 00:00:00",LastMonthEnd_" 23:59:59") Quit tSC } }
Then, when setting the task up, I would set it to run on the first Monday of the Month, and it will grab everything from the previous month.
Thank you so much Julian,
This helps a lot, it is exactly what I am looking for.
Have a look at the Structured Logging capabilities as well.