Quantcast
Channel: SCN : Unanswered Discussions - SAP Business Process Automation by Redwood
Viewing all articles
Browse latest Browse all 646

"Trying to use non-attached object TableValue"

$
0
0

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


Viewing all articles
Browse latest Browse all 646

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>