Thursday, July 28, 2011

Fitting It Into the Schedule

This title applies to more than one aspect of my Identity Management life these days. I've been very busy which accounts for the lack of blog entries lately.  It's not that I don't have what to write about.  It's more about finding the time to do it.  

I was given an interesting challenge lately.  We have a number of tasks on the current project that only need to run once a month., which is not a frequency that is supported by the IDM scheduler. There's actually a few ways to handle this. Most of which revolve around finding the batch file that is created when job is first run and tying this into the scheduling utility of your choice.

However, I was really interested in finding a way that would work within the IDM framework. So I came up with this little script:

// Main function: scheduler

function scheduler(Par){
//Only run the task on a particular day of the month.
//Should only be called from the Initialization script of a maintenance job.
//Created by: Matt Pollicove 7/7/11
//NW IDM Functions used in this script:
//NOTE: Requires an external Job Constant called Runday that is set to the
//two digit day of the month that the task should be executed on or this value
//must be hard coded

//Parameters for the task.  Name of the pass/task and what the legal execution day is
var strJobName = uGetPassSubject();
var strRunOnThisDay = '%$runday%';

//What's today's date and what is the actual date.
var strDate = '%$';
var strToday = strDate.substring(3,5);

//Put it all together
if (strToday != strRunOnThisDay){
     uWarning(strJobName + " is not scheduleItd to run on " + strDate);

As you can see, it's not terribly complicated, but let's break it down:

The task first grabs the name of the running task for informational purposes.  Then it goes out to find a local constant (feel free to make an adjustment so that it works with a repository or global constant) which holds the day of the month the task should run on.

Once we have this, we do basically the same day with the current date, by getting it from the system parameter %$, and retrieving the date part of the current month.

Then we can compare the two values. If they're equal go ahead, if not, we log a message (another thing that can be taken out if desired) and call uStop().

  1. Now to use this functionality we need to do the following:
  2. Copy/Paste the script listing above into a NW IDM script.
  3. Create the RUNDAY constant.  Remember if you choose to create this as anything other than a job constant, you need to edit the script accordingly.
  4. This script could be used in either a managed task (yellow folder section) or a work flow task (although I'm not sure why). But the script should be placed in the "Initialization script" entry on the source tab of the first pass in the job. When running as a managed task, it should be scheduled to run once every 24 hours.

That's about it.  Hope this works for you.  Please remember to share any edits or improvements.
Post a Comment