Fine-tuning automations with the TimeSpan method

Introduction

In some scenarios, automations need to rely not only on specific dates but also on time windows relative to those dates. The TimeSpan method lets you build conditions based on how much time has passed (or will pass) between two events, enabling more precise, flexible automation logic.

Below are two common use cases that demonstrate how TimeSpan can be applied in real-world identity lifecycle scenarios.

Use Case 1: Provisioning accounts before the hire date

Problem

When provisioning user accounts for new hires, it's common to wait until the employee’s start date. However, IT teams often need access a few days in advance to ensure everything is ready on day one. Provisioning an account on the actual start date might not provide enough lead time for these critical setup tasks.

Solution

To give IT teams time to prepare before a new hire starts, you can use the TimeSpan method to trigger provisioning within a defined window before the start date. For example, to provision accounts up to three days in advance, use the following condition:

Employment.EmployeeStatusCode == "A" && 
DateTime.Now - Employment.LastHireDate <= TimeSpan.FromDays(3)

This checks that the employee is active ("A") and their hire date is within the specified time window. It ensures provisioning happens early enough for setup, without triggering too far in advance.

Use Case 2: Moving terminated users to a different OU 90 days after termination
Problem

After an employee is terminated, their account is moved to a temporary OU hosting recently terminated users. Once a specified period has passed, the organization wants to move these accounts to a separate OU for long-term archival.

Solution

You can use the TimeSpan method to identify users who were terminated more than 90 days ago and automatically move them to a different OU using the following condition:

WHEN
Employment.EmployeeStatusCode == "T" && 
(DateTime.Now - Employment.DateOfTermination) >= TimeSpan.FromDays(90)
THEN
Move to the designated OU


This condition checks that:

  • The employee status is terminated ("T")
  • At least 90 days have passed since the termination date

Once the condition is met, the automation can move the user to the designated OU.

Summary

The TimeSpan method is a useful way to control when automations run based on time, not just dates. Whether you're provisioning accounts early, delaying deactivations, moving through different OUs, or adding grace periods, TimeSpan offers precise timing control.

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.