Click HERE to see how Saviynt Intelligence is transforming the industry. |
08/09/2024 05:11 AM - edited 08/09/2024 05:16 AM
This is for AD Service Accounts . We have a condition for REMOVEACCOUNTACTION where it will check if the validthrough (there is one dynamic attribute Validity which is storing the value in validthrough) date is within last 90 days from todays date, it will disable the account & move to disable ou. But if the validthrough date is not within last 90 days, it will delete the account.
I am using the below format, but everytime its executing the if condition i.e. deleting the account, its not going to the else condition even when the validthrough is set as future date.
${ Map map1 = new HashMap(); Date curDate = new Date(); Date prevDate = curDate -90; if(Date.parse("dd-MM-yyyy", Validity) < prevDate.format("dd-MM-yyyy")) { map1.put('removeAction','DELETE'); } else { map1.put('removeAction','SUSPEND'); map1.put('userAccountControl','514'); map1.put('moveUsertoOU','<disabled ou>'); map1.put('deleteAllGroups','Yes'); } jsonBuilder = new groovy.json.JsonBuilder(map1); return jsonBuilder.toString(); } |
Assuming that the issue is with date, I have tried to check with mutiple format. But everytime its following the IF condition.
Solved! Go to Solution.
08/09/2024 05:59 AM
Map map1 = new HashMap();
Date curDate = new Date();
Date prevDate = curDate - 90;
Date validthroughDate = Date.parse("dd-MM-yyyy", Validity);
if (validthroughDate < prevDate) {
map1.put('removeAction','DELETE');
} else {
map1.put('removeAction','SUSPEND');
map1.put('userAccountControl','514');
map1.put('moveUsertoOU','<disabled ou>');
map1.put('deleteAllGroups','Yes');
}
jsonBuilder = new groovy.json.JsonBuilder(map1);
return jsonBuilder.toString();
08/09/2024 06:16 AM
Hi @rushikeshvartak thank you for your quick response. Its not working, still the account is getting deleted. Is there a way to print/log these date type variables ?
08/09/2024 06:21 AM
Breaking json 😂
08/23/2024 03:16 AM
anyone who can help/guide on this?
08/26/2024 09:08 AM
For future reference, below one worked for me:
{ "removeAction": "${Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, -90); if((account.validthrough.getTime() < calendar.getTimeInMillis())) {'DELETE'} else {'SUSPEND'}}", "moveUsertoOU": "<disabled OU>", "deleteAllGroups": "Yes", "userAccountControl": "514" } |