Acknowledge all failed instances of a job when the job succeeds

Language: C#

View on GitHub to download or comment.

See the User script help topic for additional information.

Samples index

This script acknowledges all failed instances for the executing job. It can be used to automatically acknowledge previous failures for the job when the job succeeds

Usage

Note: The user account the job is running under must have an adTempus login with permission to execute the job. This is necessary so the API can acknowledge the instances.

Create a new Shared Script named "Acknowledge all instance for executing job". Set the language to C# and paste in the sample code as the script body. Click OK to save the script.

Edit the job where you want to use the script. Add a Response with an event to trigger it on successful exection. Add a script action and select the new Shared Script as the script to execute.

When the job succeeds and the script is invoked, it gets the identity of the job, then uses the API to fetch the job and acknowledge all failed instances.

sample.cs
/*
This script acknowledges all failed instances for the currently-executing job.

The user account that the job is running under must have a login in adTempus, with permission to Execute the job.
*/
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using ArcanaDevelopment.adTempus.ApplicationIntegration;
using ArcanaDevelopment.adTempus.Client;
using ArcanaDevelopment.adTempus.Shared;


namespace UserScript
{
    public class UserScript : ArcanaDevelopment.adTempus.ApplicationIntegration.UserScriptBase
    {
        public override Object Run()
        {
			//get the identity of the running job and create an OID
			var jobID=adTempus.JobVariables["ADTJobID"];
			var jobOID=new OID(ClassID.Job, new Guid(jobID));
			
			//Connect to the local adTempus server, using Windows authentication.
			using(var scheduler=Scheduler.Connect(adTempus.JobVariables["ServerAndInstanceName"],LoginAuthenticationType.Windows, "", ""))
			{
				using(var context=scheduler.NewDataContext())
				{
					var job=context.GetObject(jobOID) as Job;
					job.AcknowledgeAllInstances();
				}
			}
			return 0;
        }
    }
}

Comments

View on GitHub to comment.