HowTo: Execute Workflow Activities at a Specified Date in User Application

wschreiber

By: wschreiber

June 10, 2010 2:20 pm

Reads: 424

Comments:0

Rating:0

Sometimes you may want to start a workflow, but delay specific parts of the workflow until a specified date or time has come: A new user might need to be created at a certain date, a workflow action should be performed at midnight, an object needs to be created at one time and be deleted some time later.

While all of these actions could be performed by IDM drivers, it may often be more flexible, easier and a matter of minutes to add such delays in the workflow itself.

The idea behind this concept is to create a “Dummy Approval” with a programmatically calculated timeout.

A request sits in the approval queue of this Dummy Approval and waits for the specified date/time to come.

Once the timeout has been reached, the workflow continues and the subsequent activities are processed.

There is no actual need to use a “real” user for the Dummy Approval, since all we need is wait for the timeout.

However, if you wish, you may even utilize the option that you CAN open the Dummy Approval form and manually approve or deny the request if needed.

The sample workflow attached to this note can be imported into IDM Designer if you like. This allows you to review or copy the relevant elements into your own workflows.

To implement the delayed approval I have created a very simple request form with a date picker.

The “Dummy Approval” form contains not much more than a field to display the selected date.

Two mapping activities have been added to calculate the required timeout:

  • The first mapping activity “Calculate Execution Time” converts the date input to a Java Date (milliseconds since 1970)
    function getStartTime() {
      var currentTime     = (new Packages.java.util.Date()).getTime();
      // e.g., currentTime=1246042183027
      var startTime       = currentTime; // default
      try
      {
        // get customStartDate as String
        var customStartDate   = flowdata.get('start/request_form/fldTargetDate');
        //  e.g., customStartDate=20100630140000000+0200
    
        // use YYYYMMDD substring (keep date, set time to midnight)
        customStartDate    = customStartDate.substring( 0, 8 ) + '000000';
        //  e.g., customStartDate=20100630000000
    
        // convert string to time (ms)
        startTime = (new Packages.java.text.SimpleDateFormat( "yyyyMMddHHmmss" )).parse( customStartDate ).getTime();
        //  e.g., startTime=1246312800000
      }
      catch ( e )
      {
      }
      return( startTime );
    };
    
    getStartTime();
    

    The result is stored in flowdata.

  • The second mapping activity “Calculate Timeout” calculates the difference between the date input and the current time (in milliseconds)

    function getTimeout() { 
    
    	var timeout = 1000;	// default timeout: 1 sec
    	try
    	{
    		// get current time
    		var currentTime 	= (new Packages.java.util.Date()).getTime();
    		// get scheduled start time
    		var customStartDate 	= flowdata.get('start/custom/executionTime');
    		// if time has not yet come, calc timeout in ms
    		if ( customStartDate > currentTime )
    		{
          		timeout = customStartDate - currentTime;
    		}
    	}
    	catch ( e ) {}
    
    	return timeout ;
    };
    
    getTimeout();
    

  • The result is stored in flowdata.

All that remains to do is to specify the “Dummy Approval” details:

Display some info from the request:

Leave escalation open,

Select a dummy approver of your choice (e.g., some Admin account), and enter the calculated timeout.

You’re ready to go.

A request you submit will stay in the “Dummy Approval” queue until it times out, or until the selected approver manually approves or denies the request.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Tags: , , ,
Categories: Uncategorized

Disclaimer: As with everything else at NetIQ Cool Solutions, this content is definitely not supported by NetIQ, so Customer Support will not be able to help you if it has any adverse effect on your environment.  It just worked for at least one person, and perhaps it will be useful for you too.  Be sure to test in a non-production environment.

Comment