You can use ScheduledActionService to do most of the actions you can do on the Scheduled Actions tool page. Also like the tool, you cannot update scheduled actions. You can only delete or deactivate existing actions.
When you create a scheduled action using the API, you reference a Java class in the Scheduled Actions folder. If the Java class is not in the folder, you can add it through the API using DocumentService. The name of the Java class in the following code sample is ActionClass.
public class MyRule extends CustomAction<Project> {
@Override public void action(Project project) { //the action class for the scheduled action. Class<ActionClass> actionClass = ActionClass.class;
// Retrieve the service ScheduledActionService scheduledActionService = platform.getScheduledActionService();
// Build parameters Parameters parameters = scheduledActionService.newParameters(); parameters.addBooleanParameter("isAThing", "This is a thing", false); parameters.addProjectParameter("triggeringProject", "Project responsible for the action", project);
//create a new weekly schedule. Calendar cal = Calendar.getInstance(); cal.set(2014, 06, 19); Schedule schedule = Schedule.createWeekly(cal.getTime(), 2); ScheduledActionStatus generatedUniqueId = scheduledActionService.scheduleAction(actionClass, parameters, schedule); } }
public class ActionClass extends ScheduledCustomAction {
@Override public void action() { // Repeated action code } } |
If you want to get a scheduled action from the tool, you can use the getScheduledAction() method, as shown in the following sample.
ScheduledActionStatus scheduledActionStatus = scheduledActionService.getScheduledAction("uniqueName"); |
If you want to deactivate a scheduled action using the API, you can use the deactivate() method, as shown in the following sample.
scheduledActionService.deactivate("uniqueName"); |