cancel
Showing results for 
Search instead for 
Did you mean: 

Redwood script - NPE for duplicate(), but the job exists.

nanda_kumar21
Active Contributor
0 Kudos

Hi Everyone,

M33.104 - build version.

I'm tried the following code


{

JobDefinition newABAPJob = jcsSession.getJobDefinitionByName("DUP_TEST");

if (newABAPJob == null) {

newABAPJob = jcsSession.getJobDefinitionByName("SAP_AbapRun").duplicate();

newABAPJob.setName("DUP_TEST");

jcsSession.persist();

}

else {

jcsOut.println("JobDefinition already exists");

}

}

When i replaced SAP_AbapRun with a job definition i already have (as below), i received a Null Pointer Exception.


newABAPJob = jcsSession.getJobDefinitionByName("ECC_FIN_AP_TEMPLATE").duplicate();

Error:

57 more
Caused by: java.lang.NullPointerException: while trying to invoke the method com.redwood.scheduler.api.model.JobDefinition.duplicate() of a null object returned from com.redwood.scheduler.api.model.SchedulerSession.getJobDefinitionByName(java.lang.String)
at com.redwood.scheduler.custom.ShellScript_nandak.execute(ShellScript_nandak.java:17)
at com.redwood.scheduler.custom.ShellScript_nandakStub.jcsExecute(ShellScript_nandakStub.java:20)
... 62 more

The Job definition exists - screenshot below. The job is not a template. I tried with different job definitions that i created, it always failed.

But when i used SAP_AbapRun or SAP_AbapRunPrint, it is successful.


Please let me know what am i doing wrong?



Thanks

Nanda

Accepted Solutions (1)

Accepted Solutions (1)

gmblom
Active Contributor
0 Kudos

Hi Nanda,

You are looking up the job definition in the wrong partition. As you do not provide the partition to lookup in, GLOBAL is assumed. You can try the following two alternatives:

  1. newABAPJob = jcsSession.getJobDefinitionByName(jcsSession.getPartitionByName("FIN"), "ECC_FIN_AP_TEMPLATE").duplicate();

newABAPJob = BusinessKeyLookup.getJobDefinitionByBusinessKey(jcsSession, JobDefinition.OBJECT_TYPE + ":FIN.ECC_FIN_AP_TEMPLATE").duplicate();

Regards Gerben

nanda_kumar21
Active Contributor
0 Kudos

Thanks a lot Gerben. It worked.

One more question, so when i duplicate the job gets created under global partition by default and i have to use the setPartition() to set it explicitly?

Thanks

Nanda

gmblom
Active Contributor
0 Kudos

Hi Nanda,

I don't know. Sometimes things are just the way they are.

Regards Gerben

nanda_kumar21
Active Contributor
0 Kudos

I just executed in shell and confirmed that by default, the job gets created under Global partition and we have to explicitly set the partition.

Thanks

Nanda

Answers (0)