1 Reply Latest reply: Jan 16, 2013 11:44 AM by aengineer RSS

    Sample Code for invoking Scheduled Task With Parameters


      Does anyone have some sample code for invoking a scheduled task via the OIM API's, while specifying values for parameters.

      What I am trying to do is to invoke the "Job History Archival" task with a value for the "Archive Date" parameter to be equivalent to "today - 7". I would have preferred if I could simply provide the parameter value via the Admin UI as 'sysdate-7' or 'to_char(sysdate-7,'DDMMYYYY')', but the UI does not allow such parameter values. It seems to be expecting a hard coded value in MMDDYYYY format.

      Aspi Engineer
      Putnam Investments
        • 1. Re: Sample Code for invoking Scheduled Task With Parameters
          never mind. Here is the code to do what I wanted to do.

                    // Compute a string that equates to (today - 7) in "DDMMYYYY" format.
                    Date today = new Date();
                    Long archiveDateMillis = today.getTime() - (7 * 24 * 60 * 60 * 1000);
                    Date archiveDate = new Date(archiveDateMillis);
                    // Format the archive date into DDMMYYYY format.
                    SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy");
                    String archiveDateString = sdf.format(archiveDate);

                    // Load the SchedulerService, and get the job details for the archival job.
                    SchedulerService service = oimClient.getService(SchedulerService.class);
                    JobDetails[] detailsArray = service.getJobDetails("Job History Archival");
                    JobDetails archiveJobDetail = detailsArray[0];
                    // Get the job parameters
                    HashMap<String, JobParameter> params = archiveJobDetail.getParams();
                    JobParameter archiveDateParam = params.get("Archival Date");
                    JobParameter opTypeParam = params.get("Operation Type");

                    // Update the job detail with the new parameter values
                    log.info("Updating job 'Job History Archival' with archive date of [" + archiveDateParam.getValue() + "] and operation type of [" + opTypeParam.getValue() + "]");          
                    archiveJobDetail.getParams().put("Archival Date", archiveDateParam);
                    archiveJobDetail.getParams().put("Operation Type", opTypeParam);

                    // Instruct the scheduler service to update the job, which now has the new parameter values
                    // Run the job
                    service.triggerNow("Job History Archival");