Set and store Parameter values when creating or updating a Setup

Follow

Set Parameter values when creating or updating a Setup with SDK

This sample script is written to create a Setup, add Jobs with Parameters to the new Setup, then override the value of those Parameters inside of the Setup Job using the JAMS SDK. 

NOTE: This code is a sample and must be changed to reflect the user's needs before use. Running the following code in as-is may cause unexpected results.  

using MVPSI.JAMS;

namespace CreateSetup
{
class Program
{
static void Main(string[] args)
{
Server server = Server.GetServer("localhost");
Setup setup;

if (Setup.Exists("Samples\\AddedByCode"))
{
//
// Delete it so it can be added again
// Skip this step unless you wish to delete and replace an existing setup
//
Setup.Delete("Samples\\AddedByCode");
}

//
// Create a Setup
//
setup = new Setup();
setup.SetupName = "AddedByCode";
setup.ParentFolderName = "Samples";

//
// Add a job that has parameters
//
SetupJob job1 = new SetupJob();
job1.JobName = "Sleep60";
job1.IsRelative = true;
setup.Jobs.Add(job1);

//
// Add a job that has parameters
//
SetupJob job2 = new SetupJob();
job2.JobName = "CheckDB";
job2.IsRelative = true;
setup.Jobs.Add(job2);

//
// Save the changes
//
setup.Update(server);

//
// Save and reload before setting parameter values
// JAMS does not load the parameters when adding a job, only when
// loading the setup
//

//
// Load the setup that was just created
//
Setup.Load(out setup, "AddedByCode", "Samples", server);

//
// Find the CheckDB job
//
foreach (var j in setup.Jobs)
{
if (j.JobName == "CheckDB")
{
//
// Find and set the parameter on this job.
// Repeat for each parameter to be set.
//
foreach (var p in j.Parameters)
{
if (p.ParamName == "DBNAME")
{
p.DefaultValue = "MYDatabase";
}
}
}
}

setup.Update(server);
}
}
}

Other examples may be available upon request.

Have more questions? Submit a request

Comments