Language: C#
View on GitHub to download or comment.
See the User script help topic for additional information.
This script uses the adTempus API to get an ExecutionHistoryItem representing the job instance in which the script is running. You can use this to get detailed information about the instance and its steps. In this example the script logs messages giving the status for each step that has executed so far.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ArcanaDevelopment.adTempus.ApplicationIntegration;
using ArcanaDevelopment.adTempus.Shared;
using ArcanaDevelopment.adTempus.Client;
namespace UserScript
{
public class UserScript : ArcanaDevelopment.adTempus.ApplicationIntegration.UserScriptBase
{
public override Object Run()
{
//get the identity of the running instance from the JobVariable. Note that this won't be set if you test the script outside of a running job, so this will fail.
var instanceOID=new OID(ClassID.ExecutionHistoryItem,Guid.Parse(adTempus.JobVariables["ADJobInstance"]));
//connect to adTempus using the API. Note that the use account used for the job must have permission to log in to adTempus and view the job
using(var scheduler=Scheduler.Connect(adTempus.JobVariables["ServerAndInstanceName"],LoginAuthenticationType.Windows, "", ""))
{
using(var context=scheduler.NewDataContext())
{
//Get the ExecutionHistoryItem representing the active instance (documentation.arcanadev.com/adtempus/api/5.1/ArcanaDevelopment.adTempus.Client~ArcanaDevelopment.adTempus.Client.ExecutionHistoryItem.htm)
var instance=(ExecutionHistoryItem)context.GetObject(instanceOID);
//Sort the steps by step number and iterate through them. Write a log message showing the status of each step
foreach(var step in instance.Steps.OrderBy(x=>x.StepNumber))
{
adTempus.LogMessage(MessageTypeEnum.Informational, 0, $"Step {step.StepNumber}: {step.Status}");
}
}
}
return 0;
}
}
}
View on GitHub to comment.