Leaver Automation on basis of ContractEndDate

Hi All.
The requirement was to rigger a leaver event when ContractEndDate attribute of an application matches todays date , such that if it matches the leaver event is triggered and the identity moves in an ou named DIsabledOu.

My approach was to build a lifecycleevent and event type as rule in which the rule is as below :
import java.util.Date;
import java.text.SimpleDateFormat;

log.info(“Running ContractEndDateLeaverTriggerRule…”);

if (identity == null) {
log.warn(“Identity object is null”);
return false;
}

log.info("Evaluating identity: " + identity.getName());

Object endDateObj = identity.getAttribute(“contractEndDate”);

if (endDateObj == null) {
log.info("No contractEndDate found for identity: " + identity.getName());
return false;
}

Date today = new Date();
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);

String todayStr = sdf.format(today);
String endDateStr = sdf.format((Date) endDateObj);

log.info("Today’s date: " + todayStr + ", Contract End Date: " + endDateStr);

if (todayStr.equals(endDateStr)) {
log.info("Match found: triggering leaver for identity " + identity.getName());
return true;
} else {
log.info("No match for " + identity.getName());
return false;
}

In the business process i have my leaver event selected
but this is not working and throwing errors .

Can anyone please help in this regard ?

why dont you use the rapid setup?

and can you post the error?

1 Like

Hi Thanks for your reply
The error is : Exception running rule: BeanShell script error: bsh.EvalError: Sourced file: inline evaluation of: import java.util.Date; import java.text.SimpleDateFormat; log.info("Running Co . . . '' : Attempt to resolve method: getName() on undefined variable or class name: identity : at Line: 12 : in file: inline evaluation of: import java.util.Date; import java.text.SimpleDateFormat; log.info("Running Co . . . ‘’ : identity .getName ( )
BSF info: ContractEndDateLeaverTriggerRule at line: 0 column: columnNo

How can i do this using Rapid Setup ? Can you please guide me .

Hi @uditsahntl01

Use newIdentity instead of identity as identity is not argument passed inside IdentityTrigger rule.

Use below link to know about rapid setup,

you can activate the leaver in rapid setup conf:


and set a trigger on the date


In this case also its not triggering the business process selected above

Hi and Hello,

try something like this:

import java.util.Date;
import java.text.SimpleDateFormat;

log.info("Running ContractEndDateLeaverTriggerRule...");

// Safety check: make sure identity is not null
if (identity == null) {
    log.warn("Identity object is null. Exiting rule.");
    return false;
}

String identityName = identity.getName();
log.info("Evaluating identity: " + identityName);

// Get the contractEndDate attribute from the identity
Object endDateObj = identity.getAttribute("contractEndDate");

if (endDateObj == null) {
    log.info("No contractEndDate found for identity: " + identityName);
    return false;
}

if (!(endDateObj instanceof Date)) {
    log.warn("contractEndDate is not of type Date for identity: " + identityName);
    return false;
}

// Get today's date and format both dates for comparison (ignoring time)
Date today = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

String todayStr = sdf.format(today);
String endDateStr = sdf.format((Date) endDateObj);

log.info("Today's date: " + todayStr + ", Contract End Date: " + endDateStr);

// Check if dates match
if (todayStr.equals(endDateStr)) {
    log.info("Dates match. Triggering leaver event for identity: " + identityName);
    return true;
} else {
    log.info("Dates do not match for identity: " + identityName);
    return false;
}

Fixed Area What Was Done
identity == null Added check before using it to avoid null pointer exception
Typographic quotes ( vs ") Replaced with correct syntax quotes
contractEndDate is not Date Added instanceof Date check to avoid ClassCastException
Date comparison Normalized date format (yyyy-MM-dd) to ignore time difference

Regards,
Adam