cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CPS replace parameter value of all job definitions of type CMD

former_member1244799
Participant
0 Kudos

Hi All,

I am using the below Redwood script to update the parameter "DIRECT" of job definition "FILE_RENAME_PARAM". I am getting the parameter value from "PARAM_TRANSLATION" table. The column in the table is "TARGET". Can you please advise how can I change the below script to update the parameter "DIRECT" of ALL job definitions of type "CMD" using the below Redwood script.

{
     
      JobDefinition jobDefinition = jcsSession.getJobDefinitionByName("FILE_RENAME_PARAM");
      if (jobDefinition.getName().equals("FILE_RENAME_PARAM"))

      {
        JobDefinitionParameter parameterDIR = jobDefinition.getJobDefinitionParameterByName("DIRECT");
      
        if (parameterDIR != null)
        {
          String defaultExpression = parameterDIR.getDefaultExpression();
          if (defaultExpression != null)
          {
            Table table = jcsSession.getTableByName("PARAM_TRANSLATION");
            if (table != null)
            {
              TableValue tableValue  = table.getTableValueBySearchKeySearchColumnName(defaultExpression, "TARGET");

              String targetInstance  = null;

              if (tableValue != null)
              {
                targetInstance  = table.getTableValueBySearchKeySearchColumnName(defaultExpression, "TARGET").getColumnValue();
               jcsOut.println(targetInstance);
                parameterDIR.setDefaultExpression(targetInstance);
               jcsSession.persist();

               
              }
              else
              {
                throw new Exception("Key " + defaultExpression + " (from job definition " + jobDefinition.getName() + ") was not found in table PARAM_TRANSLATION");
              }

   
 
                             
            }
          }
        }
      }
    }

Thank you so much in advance.

Regards,

Ramana

Accepted Solutions (1)

Accepted Solutions (1)

nanda_kumar21
Active Contributor
0 Kudos

Add the above script into a for loop.

For(Iterate through result set returned for a select query on Job Definition table where JobDefinitionType=CMD)

{

//cast the iterator object to JobDefinition

JobDefinition jd = (JobDefinition)i<IteratorObject>.next();

//your code here

}

thanks

Nanda

former_member1244799
Participant
0 Kudos

Thank you Nanda.

I did the looping in the following way. I added the below lines of code to the above script.

{
 
     String query = "select JobDefinitionParameter.* from JobDefinitionParameter where JobDefinitionParameter.Name = 'DIRECT'";
     for (Iterator it = jcsSession.executeObjectQuery(query, null); it.hasNext();)

{


      {
       
       JobDefinitionParameter parameterDIR = (JobDefinitionParameter)it.next();
 
          if (parameterDIR.getDefaultExpression()!= null)
        {
          String defaultExpression = parameterDIR.getDefaultExpression();
          if (defaultExpression != null)
          {
            Table table = jcsSession.getTableByName("PARAM_TRANSLATION");
            if (table != null)

Regards,

Ramana

former_member1244799
Participant
0 Kudos

Hi Nanda or any one,

When I run the above code. I am getting the below error. Please advise what to change.

Caused by: JCS-122035: Unable to persist: JCS-102090: Object 'Job Definition FILE_COPY_PARAM (Copy from 2015/01/12 15:29:43,477 America/New_York)' of type Job Definition cannot be modified

at com.redwood.scheduler.model.SchedulerSessionImpl.writeDirtyListLocal(SchedulerSessionImpl.java:934)

at com.redwood.scheduler.model.SchedulerSessionImpl.persist(SchedulerSessionImpl.java:875)

at com.redwood.scheduler.custom.PARMETER_TRANSLATION_REPLACE_PARAM_ALL_JOBS_TABLEexecute(PARMETER_TRANSLATION_REPLACE_PARAM_ALL_JOBS_TABLE.java:user code 32)

at com.redwood.scheduler.custom.PARMETER_TRANSLATION_REPLACE_PARAM_ALL_JOBS_TABLEStub.jcsExecute(PARMETER_TRANSLATION_REPLACE_PARAM_ALL_JOBS_TABLEStub.java:28)

... 13 more

Caused by: com.redwood.scheduler.model.exception.NonModifiableObjectException: JCS-102090: Object 'Job Definition FILE_COPY_PARAM (Copy from 2015/01/12 15:29:43,477 America/New_York)' of type Job Definition cannot be modified

at com.redwood.scheduler.model.method.impl.BranchedUniqueNamedApplicationObjectMethodImpl.vetoPhaseHandler(BranchedUniqueNamedApplicationObjectMethodImpl.java:154)

at com.redwood.scheduler.model.method.impl.JobDefinitionMethodImpl.vetoPhaseHandler(JobDefinitionMethodImpl.java:1058)

Regards,

Ramana

former_member1244799
Participant
0 Kudos


I also tried to change my select statement as below.

String query = "select JobDefinitionParameter.* from JobDefinitionParameter where JobDefinitionParameter.Name = 'DIRECTORY' and BranchedLLPVersion = -1";

But got the below error. Please advise.

Caused by: JCS-122036: An exception occurred during the execution of a persistence layer method

at com.redwood.scheduler.model.SchedulerSessionImpl.executeObjectQuery(SchedulerSessionImpl.java:1100)

at com.redwood.scheduler.model.SchedulerSessionImpl.executeObjectQuery(SchedulerSessionImpl.java:1083)

at com.redwood.scheduler.custom.PARMETER_TRANSLATION_REPLACE_PARAM_ALL_JOBS_TABLEexecute(PARMETER_TRANSLATION_REPLACE_PARAM_ALL_JOBS_TABLE.java:user code 4)

at com.redwood.scheduler.custom.PARMETER_TRANSLATION_REPLACE_PARAM_ALL_JOBS_TABLEStub.jcsExecute(PARMETER_TRANSLATION_REPLACE_PARAM_ALL_JOBS_TABLEStub.java:28)

... 13 more

Caused by: com.redwood.scheduler.persistence.api.PersistenceException$UnknownField: JCS-XXXXX: Unknown field BranchedLLPVersion in [JobDefinitionParameter] debug:  aliases=true {JobDefinitionParameter=JobDefinitionParameter}

at com.redwood.scheduler.persistence.api.PersistenceException$UnknownField.rethrowInternal(PersistenceException.java:193)

at com.redwood.scheduler.persistence.api.PersistenceException.rethrow(PersistenceException.java:697)

Regards,

Ramana

nanda_kumar21
Active Contributor
0 Kudos

BranchedLLPVersion is a column in JobDefinition table and you are selecting it in JobDefinitionParameter table.

select Jp.* from JobDefinitionParameter Jp,JobDefiniton Jd where Jp.Name = 'DIRECTORY' and Jp.JobDefinition=Jd.UniqueId and Jd.BranchedLLPVersion = -1

thanks

Nanda

former_member1244799
Participant
0 Kudos


Hello Nanda,

Thank you so much.

I ran the above select statement but received the below error message. Please advise.

Caused by: JCS-122036: An exception occurred during the execution of a persistence layer method

at com.redwood.scheduler.model.SchedulerSessionImpl.executeObjectQuery(SchedulerSessionImpl.java:1100)

at com.redwood.scheduler.model.SchedulerSessionImpl.executeObjectQuery(SchedulerSessionImpl.java:1083)

at com.redwood.scheduler.custom.PARMETER_TRANSLATION_REPLACE_PARAM_ALL_JOBS_TABLEexecute(PARMETER_TRANSLATION_REPLACE_PARAM_ALL_JOBS_TABLE.java:user code 5)

at com.redwood.scheduler.custom.PARMETER_TRANSLATION_REPLACE_PARAM_ALL_JOBS_TABLEStub.jcsExecute(PARMETER_TRANSLATION_REPLACE_PARAM_ALL_JOBS_TABLEStub.java:28)

... 13 more

Caused by: com.redwood.scheduler.persistence.api.PersistenceException$UnknownObjectType: JCS-XXXXX: Unknown object type JobDefiniton in  aliases=false {Jp=JobDefinitionParameter, Jd=JobDefiniton}

at com.redwood.scheduler.persistence.api.PersistenceException$UnknownObjectType.rethrowInternal(PersistenceException.java:119)

at com.redwood.scheduler.persistence.api.PersistenceException.rethrow(PersistenceException.java:697)

at com.redwood.scheduler.persistence.spi.DatabaseHelper.executeQuery(DatabaseHelper.java:106)

at com.redwood.scheduler.persistence.impl.LowLevelPersistenceImpl.executeQueryRetry(LowLevelPersistenceImpl.java:491)

at com.redwood.scheduler.persistence.impl.LowLevelPersistenceImpl.access$1(LowLevelPersistenceImpl.java:481)

at com.redwood.scheduler.persistence.impl.LowLevelPersistenceImpl$1.execute(LowLevelPersistenceImpl.java:466)

at com.redwood.scheduler.persistence.impl.InnerPersistenceUnitOfWorkManager.execute(InnerPersistenceUnitOfWorkManager.java:35)

at com.redwood.scheduler.persistence.impl.LowLevelPersistenceImpl.executeQuery(LowLevelPersistenceImpl.java:460)

at com.redwood.scheduler.cluster.persistence.ClusteredLowLevelPersistence.executeQuery(ClusteredLowLevelPersistence.java:155)

at com.redwood.scheduler.model.SchedulerSessionImpl.executeObjectQuery(SchedulerSessionImpl.java:1096)

... 16 more

Caused by: com.redwood.scheduler.persistence.api.PersistenceException$UnknownObjectType: JCS-XXXXX: Unknown object type JobDefiniton in  aliases=false {Jp=JobDefinitionParameter, Jd=JobDefiniton}

at com.redwood.scheduler.persistence.sql.parser.SqlDictionaryResolver.getTableInfoAssert(SqlDictionaryResolver.java:229)

at com.redwood.scheduler.persistence.sql.parser.SqlDictionaryResolver.resolveTableFromDataDictionary(SqlDictionaryResolver.java:208)

Regards,

Ramana

nanda_kumar21
Active Contributor
0 Kudos

there was a spelling mistake.

select Jp.* from JobDefinitionParameter Jp,JobDefinition Jd where Jp.Name = 'DIRECTORY' and Jp.JobDefinition=Jd.UniqueId and Jd.BranchedLLPVersion = -1

thanks

nanda

former_member1244799
Participant
0 Kudos

Oh my Bad. Thank you so so much. It worked like a charm.

Regards,

Ramana

Answers (0)