Hi Bill,
I'm trying to add/update variables to a Group using the code as included.
It works oke, but I need the 'Include in program's environment variable' to be set when the variable is new. How can I do that?
Thanks,
Guy
public void SetAdtGroupVariable(ref ListView lvMsg, ref int msgCnt, string groep, string var, string value)
{
using (DataContext context = aScheduler.NewDataContext())
{
try
{
var group = context.GetJobGroup(groep);
JobVariable variable = group.JobVariables.GetVariable(var);
if (variable == null)
{
// JobVariable variable = new JobVariable();
variable = (JobVariable)Convert.ChangeType(context.CreateObject(ClassID.JobVariable), typeof(JobVariable));
variable.Name = var;
variable.Value = value;
group.JobVariables.Add(variable);
msgCnt += 1;
var item1 = new ListViewItem(new[] { "(I) Variable '" + var + "' added",
msgCnt.ToString().PadLeft(4,'0') });
lvMsg.Items.Add(item1);
group.Save();
}
else
{
variable.Value = value;
group.Save();
msgCnt += 1;
var item1 = new ListViewItem(new[] { "(I) Variable '" + var + "' has been set to '" + value + "'",
msgCnt.ToString().PadLeft(4,'0') });
lvMsg.Items.Add(item1);
}
}
catch (Exception e)
{
MessageBox.Show("??" + e.ToString());
throw;
}
}
}