cancel
Showing results for 
Search instead for 
Did you mean: 

Redwood/CPS: How to access JobDefinition's source in a trigger?

0 Kudos

Hi,

I'm writing a trigger with trigger point 'Before Definition Change'.

I want to log the content of the source before the change is applied:

import java.text.MessageFormat;
import com.redwood.scheduler.api.model.JobDefinition;
{
Object o = jcsTriggerContext.getSchedulerEntity();
if (o instanceof JobDefinition)
{
JobDefinition jobDef = ((JobDefinition) o);
String msg = jobDef.getName() + "'s source will be changed. Now it's: " + jobDef.<getSource()>;
jcsOutLog.info(msg);
}
}

Could <getSource()> be replaced with something, so I could get the needed content?

Is there a reference guide where I could see the methods of the JobDefinition class?

Regards, Alexander

Accepted Solutions (0)

Answers (4)

Answers (4)

0 Kudos

Now it works - thanks!

Regards, Alexander

gmblom
Active Contributor
0 Kudos

Hello,

JobDefinitionWithSource is indeed not the correct Object type. You need Script instead:

JobDefinitionRelatedObject jdro = jd.getJobDefinitionRelatedObject();
if (jdro instanceof Script)
{
  String scriptSource = ((Script)jdro).getSource();
}

Regards Gerben

0 Kudos

Hi,

I tried the mentioned solution, but when I test with a job definition that has RedwoodScript defined, it's still of type JobDefinition (and not JobDefinitionWithSource).

How could I create an object of type JobDefinitionWithSource?

Regards, Alexander

former_member587730
Participant
0 Kudos

Hi,

Please check apidoc for more details about methods, you can find under configuration->Software .

Please refer below code which can help you to get jobdefinition source.

if (jd1.getJobDefinitionRelatedObject() instanceof JobDefinitionWithSource) { JobDefinitionWithSource jds = (JobDefinitionWithSource)jd1.getJobDefinitionRelatedObject(); jcsOut.println(jd1.getName() + ";" + jds.getSource());