We have made C# console app which takes job name and variable name and value.
C# executable is then called from python by os.system. ArcanaDevelopment API calls used to set variable value. I placed code at the bottom of the message.
We don't have any problem to set and change job variable after report generation from inside of running step. However second step being adTempus supplied SFTP uploader need to access job variable value at the time of run.
==================================================
using System;
using System.Reflection;
using ArcanaDevelopment.adTempus.Client;
using ArcanaDevelopment.adTempus.Shared;
namespace AdTempusVariableUtility
{
class Program
{
static void Main(string[] args)
{
var isGet = args.Length == 3 && args[0] == "get";
var isSet = args.Length == 4 && args[0] == "set";
if (!isGet && !isSet)
{
Console.WriteLine("This utility sets or gets the value of the given variable, for the given adTempus job.");
Console.WriteLine("Set usage: {0} set [job name] [variable name] [variable value]", AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("If a variable does not exist, it will be created, with type String.");
Console.WriteLine();
Console.WriteLine("Get usage: {0} get [job name] [variable name]", AppDomain.CurrentDomain.FriendlyName);
Environment.Exit(1);
}
string jobName = args[1];
string variableName = args[2];
using (var connection = Scheduler.Connect())
{
using (var context = connection.NewDataContext())
{
var job = context.GetJob(jobName);
var jobVariable = job.JobVariables.GetVariable(variableName);
if (isSet)
{
string variableValue = args[3];
if (jobVariable == null)
{
var newJobVariable = CreateStringVariable(context, variableName, variableValue);
job.JobVariables.Add(newJobVariable);
}
else
{
SetVariableValue(jobVariable, variableValue);
}
job.Save();
}
else if (isGet)
{
if(jobVariable==null)
throw new ApplicationException(string.Format("Variable {0} not found for job {1}", variableName, jobName));
Console.WriteLine(jobVariable.Value);
}
}
}
}
private static JobVariable CreateStringVariable(DataContext context, string variableName, string variableValue)
{
var newJobVariable = (JobVariable) context.CreateObject(ClassID.JobVariable);
newJobVariable.Name = variableName;
newJobVariable.VariableType = JobVariableType.String;
newJobVariable.StringValue = variableValue;
return newJobVariable;
}
private static void SetVariableValue(JobVariable jobVariable, string variableValue)
{
switch (jobVariable.VariableType)
{
case JobVariableType.Boolean:
jobVariable.BooleanValue = bool.Parse(variableValue);
break;
case JobVariableType.Date:
int d;
if (int.TryParse(variableValue, out d))
jobVariable.DateValue = new DateTime(d/10000, (d/100)%100, d%100);
else
jobVariable.DateValue = DateTime.Parse(variableValue).Date;
break;
case JobVariableType.DateTime:
jobVariable.DateTimeValue = DateTime.Parse(variableValue);
break;
case JobVariableType.Time:
jobVariable.TimeValue = DateTime.Parse(variableValue);
break;
case JobVariableType.Decimal:
jobVariable.DecimalValue = decimal.Parse(variableValue);
break;
case JobVariableType.Integer:
jobVariable.IntegerValue = int.Parse(variableValue);
break;
default:
jobVariable.StringValue = variableValue;
break;
}
}
}
}