Script to get the previous status.

Eduardo Menezes (20 posts)
February 22, 2021 12:41 PM
Accepted Answer

I have a JOB set up with a response that sends an email when the job has failed.

I also have a response that will re-run if the job failed.

The problem is that I received an email when it has failed, but I don't receive an email when it was re-run with Success.

I want to receive an email saying it was successful after a failed status.

Could anyone help me to write a script to get the previous status?

I appreciate any help you can provide.

Bill Staff (604 posts)
February 22, 2021 01:18 PM
Accepted Answer

There is a Job Variable names ADTJobRestartCount that gets increment for each restart (will be 0 on the first run).

So you can add a second Response to the job with event "Job Succeeded," then use a script so that the Response only runs when the restart count is > 0. In the event properties, check the option to "Use a script to determine whether the Response will be activated." Create a new script using VB.NET with the following code:

Imports System
Imports System.Collections.Generic
Imports ArcanaDevelopment.adTempus.Shared
Imports ArcanaDevelopment.adTempus.ApplicationIntegration

Public Class UserScript
    Inherits ArcanaDevelopment.adTempus.ApplicationIntegration.ResponseEventScriptBase

    Public Overrides Function Run() As Object

        Dim restartCount=CInt(adTempus.JobVariables("ADTJobRestartCount"))
        Return restartCount > 0
    End Function
End Class

If the restart count is 0 (initial run), this will return False so the response does not run. For restarts it returns True so the response runs.

 

Eduardo Menezes (20 posts)
February 23, 2021 02:45 PM
Accepted Answer

Hi, Bill thanks a lot for your attention.

In the scenario below:

 

  • Instance 1 executed with success (no email of success sent)
  • Instance 2 failed (email sent)
  • Instance 3 failed (email sent)
  • Instance 4 failed (email sent)
  • Instance 5, executed with success (this time, I would like to send an automatic email because the previous executions were failed)

Is there a way to verify if the previous status was Failed?

 

Bill Staff (604 posts)
February 23, 2021 04:19 PM
Accepted Answer

If instance 5 was run by a Response doing a job restart, then it knows that the previous status was Failed, because it's being run by a Response that only runs on failure. (It knows it's being run by a restart because the ADTJobRestartCount is > 0.)

If instance 5 is run manually or by a trigger (i.e., not by the failure response) then it has no knowledge of the previous instance. It's possible to get that by querying adTempus using the API, but it's more complicated. Is this what you're looking for--a way for it to also work if it's not run by a Response?

 

Replies are disabled for this topic.