Hello,
I wrote a script which should create one job per each row in a table. The table has two columns (key and parameter).
The script works only for the first value. Afterwards the job goes to error with the error message "Trying to use non-attached object TableValue".
May you help me to find the failure?
Source code:
import java.util.Iterator;
import com.redwood.scheduler.api.model.*;
import com.redwood.scheduler.api.model.enumeration.*;
import com.redwood.scheduler.api.scripting.variables.ScriptSessionFactory;
{
String vTableName = "TABLE1";
SchedulerSession session = ScriptSessionFactory.getSession();
Table importTable = session.getTableByName(vTableName);
if(importTable == null)
{
jcsOut.println("Table " + vTableName + " does not exist");
return;
}
// Iterator for looping through the table
Iterator iterTV = importTable.getTableValues();
while(iterTV.hasNext())
{
// Get the single table value
TableValue tv = (TableValue)iterTV.next();
// Check, if the table value belongs to a specific column
if (tv.getColumnName().equals("PARAMETER"))
{
// Get the key to identify the table row
String vkey = tv.getKey();
String strParameter = importTable.getTableValueBySearchKeySearchColumnName(vkey,"PARAMETER").getColumnValue();
// Get the job definition
JobDefinition jd = jcsSession.getJobDefinitionByName("TEST_JOBDEFINITION");
// Prepare a job based on the job definition
Job job = jd.prepare();
// Provide the other parameter values to the job
jcsOut.println("JOBNAME: " + strParameter);
job.getJobParameterByName("p_JobName").setInValueString(strParameter);
job.getJobParameterByName("jdpName").setInValueString("PRINT_PDEST");
job.getJobParameterByName("replaceValue").setInValueString("");
job.getJobParameterByName("p_ChangeJobDef").setInValueString("Y");
job.getJobParameterByName("p_TestRun").setInValueString("Y");
jcsOut.println("");
jcsSession.persist();
jcsSession.waitForJob(job);
jcsSession.refreshObjects(new SchedulerEntity[]{jd});
}
}
jcsOut.println("All requests from Table " + vTableName + " processed.");
}
Best regards
Dana