# Help needed in Leaver Disable Code

**URL:** <https://developer.sailpoint.com/discuss/t/help-needed-in-leaver-disable-code/2576>\
**Category:** IIQ Discussion and Questions\
**Created:** [January 6, 2022, 3:38pm UTC](https://developer.sailpoint.com/discuss/t/help-needed-in-leaver-disable-code/2576 "2022-01-06T15:38:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anshu77](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@anshu77](https://developer.sailpoint.com/discuss/u/anshu77)\
**Post date:** [January 6, 2022, 3:38pm UTC](https://developer.sailpoint.com/discuss/t/help-needed-in-leaver-disable-code/2576/1 "2022-01-06T15:38:13Z")

</div>

Hello Experts,

Please help me in below code as this leaver disable is running for old records too. I made some changes “New addition” to handle rehire’s exit.

```auto
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule created="1471274124177" id="1339a046568ec45b01568ec583910095" language="beanshell" modified="1641196888311" name="mycompany-IdentitySelector-LeaverDisableTrigger" type="IdentitySelector">
  <ReferencedRules>
    <Reference class="sailpoint.object.Rule" id="1339a046568ec45b01568ec57126006c" name="mycompany LifeCycle Rules Library"/>
  </ReferencedRules>
  <Signature returnType="boolean">
    <Inputs>
      <Argument name="log">
        <Description>
          The log object associated with the SailPointContext.</Description>
      </Argument>
      <Argument name="context">
        <Description>
          A sailpoint.api.SailPointContext object that can be used to query the database if necessary.</Description>
      </Argument>
      <Argument name="identity" type="Identity">
        <Description>
          The identity.</Description>
      </Argument>
    </Inputs>
    <Returns>
      <Argument name="success">
        <Description>
            True if the selection was successful; false otherwise.</Description>
      </Argument>
    </Returns>
  </Signature>
  <Source>

	import sailpoint.object.Identity;
	import sailpoint.tools.Util;
	import sailpoint.object.QueryOptions;
	import sailpoint.object.Filter;
	import sailpoint.object.IdentityRequest;
	import org.apache.commons.logging.Log;
	import org.apache.commons.logging.LogFactory;
  import java.util.Date; // New addition 
	import java.time.Duration; // New addition 
  import java.time.Instant; // New addition 

	private static Log logger = LogFactory.getLog("rule.mycompany.LCE");
	logger.debug("mycompany-IdentitySelector-LeaverDisableTrigger :: Start");
  	boolean retFlag = false;
  	// Check if the IdentityRequest has already been created for this user
 
   	try {
    Integer days = 1; // No of days duration - New addition 
		String targetId = identity.getId();
		QueryOptions qo = new QueryOptions();
		qo.add(new Filter[] { Filter.eq("targetId", targetId) });
		qo.add(new Filter[] { Filter.eq("type", "SSF LeaverDisable") });
		//qo.add(new Filter[] { Filter.ne("executionStatus", "completed") });
    	Date recentDateThreshold = Date.from(Instant.now().minus(Duration.ofDays(days))); // New addition 
      	qo.add(new Filter[] { Filter.gt("created", recentDateThreshold ) }); // New addition
		int totalRequests = context.countObjects(IdentityRequest.class, qo);
		if (totalRequests > 0) {
  // if (totalRequests > 3) {
			logger.debug("Found a open identity request for this user, totalRequests = " + totalRequests);
			return false;
		}
	} catch (Exception e) {
			logger.fatal("Exception during mycompany-IdentitySelector-LeaverDisableTrigger, Exception = " + e.getMessage());
	}
  
  	if(identity != null) {
  		logger.debug("Disable Trigger - Identity = " + identity.getName());

		//Fix to not process old records
		List links = identity.getLinks();
		if (links != null) {
			logger.debug("Number of Apps : " + links.size());
			if (links.size() &lt;= 1){
				logger.debug("Old record - no need to process");
				return false;
			}
		}

 		String status = identity.getAttribute("Status");
		logger.debug("status = " + status);

		String rStatus = identity.getAttribute("EmploymentStatus");
		logger.debug("rStatus = " + rStatus);

		if(((null != status) &amp;&amp; ("Terminated".equalsIgnoreCase(status)) &amp;&amp; (null != rStatus) &amp;&amp; ("T".equalsIgnoreCase(rStatus)))||
       		  ((null != status) &amp;&amp; ("Retired".equalsIgnoreCase(status)) &amp;&amp; (null != rStatus) &amp;&amp; ("R".equalsIgnoreCase(rStatus)))){
			String termDate = identity.getAttribute("TerminationDate");
			String disableDelete;
			if (!Util.isNullOrEmpty(termDate)) {
				if (!moreThan30Days(termDate)) {
					retFlag = true;
        			}
			}
		}
		logger.debug("retFlag = " + retFlag);
	}
	logger.debug("mycompany-IdentitySelector-LeaverDisableTrigger :: End");
  	return retFlag;

  	</Source>
</Rule>

```

---

<div class="post-metadata">

**Author:** ![adam\_creaney](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/adam_creaney/32/8971_2.png) [@adam\_creaney](https://developer.sailpoint.com/discuss/u/adam_creaney)\
**Post date:** [January 10, 2022, 5:32pm UTC](https://developer.sailpoint.com/discuss/t/help-needed-in-leaver-disable-code/2576/2 "2022-01-10T17:32:21Z")

</div>

Hi @anshu77 - Welcome to the developer community!

In order to provide accurate advice, can you please elaborate a little more on the use case here?

What are your requirements for this leaver rule, and what is the desired outcome?

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [July 19, 2023, 2:25pm UTC](https://developer.sailpoint.com/discuss/t/help-needed-in-leaver-disable-code/2576/3 "2023-07-19T14:25:26Z")

</div>


