Question
Marykutty George · Jul 7

Dynamically change output file name for a schedule task

Is there any way to dynamically generate the output filename for a schedule task?  For example when running a legacy code task every hour , is there anyway to specify the output file name to be appended with time stamp or some incrementing number to avoid overwriting ? 

 

Product version: IRIS 2021.1
0
0 187
Discussion (3)1
Log in or sign up to continue

I'm not sure about doing it through the task menu.  I would create a custom class that extends %SYS.Task.Definition and then overwrite the OnTask method with whatever custom code you want to run. For example, if you wanted to export your Business Partners to a daily file for some reason.  You could use the method below to always pull the current date.  Once you have the new class built it will be selectable in the Task Type drop down.

Method OnTask() As %Status
    {
        set tCurDate = $ZDATE($H,8)
        do ##class(Ens.Config.BusinessParnter).%ExportAll("C:\TEST\"_tCurDate_"BusinessParnters.xml")
        Quit $$$OK
    }

Interesting challenge as these are not overrideable properites of the Task Definition.

However you can hijack the device to output somewhere else.

Here is an example dynamically adding a datetime suffix to the logfile for a built-in System Task.

So if you enable Logging to "c:\temp\T" (WIndows example) on this task and selected OutputFileSuffix property "[YY]YY-MM-DD" then your Task output is actually directed to new file "c:\temp\T20220711_153600".

/// Seems to need %SYS.Task.Definition in super list to be
/// visible in Task Schedule Wizard
Class Test.SuperRunLegacyTask Extends (%SYS.Task.RunLegacyTask, %SYS.Task.Definition)
{

/// Example flexible property to enable selecting a given Date and Time format 
/// from the Schedule Wizard, to use as Suffix appended to log file name (When in use)
Property OutputFileSuffix As %String(DISPLAYLIST = ",MM/DD/[YY]YY,DD Mmm [YY]YY,[YY]YY-MM-DD,DD/MM/[YY]YY", VALUELIST = ",1,2,3,4") [ InitialExpression = 3 ];

Method OnTask() As %Status
{
	set current=$IO
	set useDev=0
	
	// Checks has at least 2 path seperators
	// Checks not a null device
	if $L($TR(current,"\/"))<($L(current)-1),$L(current,":")<2 {
		set dev=current_$TR($ZDT($ZTS,..OutputFileSuffix),", :/()-","__")
		Open dev:"NWS":2
		if $T set useDev=1
	}
	if useDev {
		use dev do {
			set tSC=##super()
			close dev	
		} while 0
	} else {
		set tSC=##super()
	}
	quit tSC
}

}

Thank you @Justin Owens  and @Alex Woodhead .  I managed to combine both your ideas and managed to create a custom task to get the system dashboard information written to a file every hour without the file getting overwritten.