Question
· Nov 11, 2021

#5003 not implemented

I am trying to create a scheduled task but get not implemented error when I try to run it.

Class PICIS.Core.Tasks.CleanEntry Extends %RegisteredObject
{

ClassMethod ClearTasks(pBackupFile As %String = "d:\Temp\BackupTasks.xml", pDelete As %Boolean = 0)
{
    // Create backup file
    Set tBackup = ##class(%Stream.FileCharacter).%New()
    Set tBackup.Filename = pBackupFile
    Do tBackup.WriteLine("<?xml version=""1.0"" encoding=""UTF-8""?>")
    Do tBackup.WriteLine("<Tasks>")

    // Delete loop
    Set tCount = 0
    Set tSC = $$$OK
    Set tRS = ##class(%SQL.Statement).%ExecDirect(, "Select ID From %SYS.Task Where Namespace = ? And TaskClass = ?", PICIS, "picis.core.tasks.senddelayedtrigger")
    While tRS.%Next() {
        Set tTask = ##class(%SYS.Task).%OpenId(tRS.ID)
        Set tSC = tTask.XMLExportToString(.tExport)
        If $$$ISERR(tSC) {
            Write !,"Problem trying to export TASK ID ",tRS.ID
            Do $System.Status.DisplayError(tSC)
            Quit
        }
        Do tBackup.WriteLine($ZConvert(tExport, "O", "UTF8"))

        // Delete?

        If pDelete {
            Set tSC = ##class(%SYS.Task).%DeleteId(tRS.ID)
            If $$$ISERR(tSC) {
                Write !,"Problem trying to delete TASK ID ",tRS.ID
                Do $System.Status.DisplayError(tSC)
                Quit
            }
        }
        Set tCount = tCount + 1
    }
    // Close backup file
    Do tBackup.WriteLine("</Tasks>")
    Set tSC = tBackup.%Save()
    If $$$ISERR(tSC) {
        Write !,"Problem saving backup file"
        Do $System.Status.DisplayError(tSC)
        Quit
    }
    Write !!,"Backed up ",$Select(pDelete:"and Deleted ", 1:""),tCount," Tasks"
}
}

Product version: Caché 2017.1
Discussion (14)0
Log in or sign up to continue

To use something in the task scheduler, you have to create a class that extends %SYS.Task.Definition. Within that class you have to define:

Method OnTask() As %Status{
    //The stuff you want to happen when the task is scheduled goes here.
    //In your case, that probably means calling your task method.
}

If that method is not defined, you get the "Not Implemented" error. If you've created such a class, make sure the method had the right name, isn't a classmethod, is As %Status, and does return a %Status. Also make sure the class is compiling correctly.