How to access 'NextRun' variable of a job using GetJobVariable() - VisualCron - Forum

Community forum

Jithin
2017-06-08T09:36:43Z
I have been trying to access the 'NextRun' variable of a job.
foreach (var job in server.Jobs.GetAll())
{
Response.Write("Task Name : " + job.Name + "<br />Next Run : " + job.GetJobVariable("NextRun") + "<br />");
}
This gives me a NullReference Exception every time. Is there any other work around?
thomas
2017-06-08T11:04:42Z
This has nothing to do with the api itself. It's Reponse.Write that throws the exception if you have null values in the input. Assign to a variable and you will see

Dim j as string
j = "Task Name : " + job.Name + "<br />Next Run : " + job.GetJobVariable("NextRun") + "<br />"

and the exception comes here is my guess:

Response.Write(j)
Support
2017-06-09T08:32:49Z
Here is some code from the Client in VB.NET:

    Public Shared Function GetNextExecutionTime(ByVal j As JobClass) As String
        If j.Stats.Active Then
            If j.Stats.DateNextExecution.Year = Date.MinValue.Year Then
                Return LangAPI.GetWord("Never")
            Else
                If ConnectionAPI.CurrentServer.On Then
                    Return TimeAPI.GetDateAdjustedToTimeZoneString(ConnectionAPI.CurrentServer, j.Stats.DateNextExecution)
                Else
                    Return LangAPI.GetWord("Server off")
                End If
            End If
        Else
            Return LangAPI.GetWord("Inactive")
        End If
    End Function

Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
bweston
2017-06-09T12:09:14Z
Not sure if this will help, but I do a lot of manipulation of the API from powershell, and GetJobVariable doesn't enter into my determining the next run...I use $job.Stats.DateNextExecution.
Scroll to Top