Need Help with Date Compare Transform

Hi All,

Looking for some help in figuring out the issue with a transform.

Below is transform that compares Hire/Start Date with current date/time and based on the no. of days difference, set a static value, for example EXPIRESIN5DAYS. This transform is then used to send out password expiration notifications. The transform is working fine except in condition, which is what I am trying to solve. For a user, if the start or hire date is 03/18/2025 ,so the transform should return value EXPIRESIN5DAYS on 03/18/2025 (Day 0), EXPIRESIN4DAYS on 03/19/2025 (Day 1), EXPIRESIN3DAYS on 03/20 (Day 2), EXPIRESON2DAYS (Day 3), EXPIERSIN1DAY (Day 4) and EXPIRED on Day5. However if you see on the screenshot, below, the transform is changing from FALSE to EXPIRESIN5DAYS and then to EXPIERSIN4DAYS on the 03/18 start/hire date itself, causing the notifications to be sent out 1 day early.

I did tried adding an offset of 5h but that didn’t helped.
Any pointers on the issue?

{
    "name": "Flag - New Joiner AD Password Expiration",
    "type": "static",
    "attributes": {
        "lifecycleState": {
            "type": "firstValid",
            "attributes": {
                "values": [
                    {
                        "type": "identityAttribute",
                        "attributes": {
                            "name": "cloudLifecycleState"
                        }
                    },
                    "INVALID"
                ]
            }
        },
        "adAccountCheck": {
            "type": "static",
            "attributes": {
                "adFirstValid": {
                    "type": "firstValid",
                    "attributes": {
                        "values": [
                            {
                                "attributes": {
                                    "sourceName": "CLIENT Active Directory",
                                    "attributeName": "sAMAccountName"
                                },
                                "type": "accountAttribute"
                            },
                            "ADNOTFOUND"
                        ]
                    }
                },
                "value": "#if($adFirstValid==\"ADNOTFOUND\")ADNOTFOUND#{else}ADFOUND#end"
            }
        },
        "newJoinerCheck": {
            "type": "dateCompare",
            "attributes": {
                "firstDate": {
                    "type": "dateFormat",
                    "attributes": {
                        "inputFormat": "EPOCH_TIME_WIN32",
                        "outputFormat": "ISO8601",
                        "input": {
                            "type": "firstValid",
                            "attributes": {
                                "values": [
                                    {
                                        "type": "accountAttribute",
                                        "attributes": {
                                            "sourceName": "CLIENT Active Directory",
                                            "attributeName": "pwdLastSet"
                                        }
                                    },
                                    "441481875030000000"
                                ]
                            }
                        }
                    }
                },
                "secondDate": {
                    "type": "dateFormat",
                    "attributes": {
                        "inputFormat": "yyyy-MM-dd",
                        "outputFormat": "ISO8601",
                        "input": {
                            "type": "firstValid",
                            "attributes": {
                                "values": [
                                    {
                                        "type": "accountAttribute",
                                        "attributes": {
                                            "sourceName": "CHGE Workday",
                                            "attributeName": "HIRE_DATE__c"
                                        }
                                    },
                                    {
                                        "type": "accountAttribute",
                                        "attributes": {
                                            "sourceName": "CLIENT NERM Contractors",
                                            "attributeName": "Start_Date"
                                        }
                                    },
                                    "2000-01-01"
                                ]
                            }
                        }
                    }
                },
                "operator": "lt",
                "positiveCondition": "true",
                "negativeCondition": "false"
            }
        },
        "sameDayHireCheck": {
            "type": "dateCompare",
            "attributes": {
                "firstDate": {
                    "type": "dateFormat",
                    "attributes": {
                        "input": {
                            "type": "substring",
                            "attributes": {
                                "input": {
                                    "type": "firstValid",
                                    "attributes": {
                                        "values": [
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CLIENT Active Directory",
                                                    "attributeName": "accountExpires"
                                                }
                                            },
                                            "01/01/2000"
                                        ]
                                    }
                                },
                                "begin": 0,
                                "end": 10
                            }
                        },
                        "inputFormat": "MM/dd/yyyy",
                        "outputFormat": "ISO8601"
                    }
                },
                "secondDate": {
                    "type": "dateMath",
                    "attributes": {
                        "expression": "+5d/d",
                        "roundUp": false,
                        "input": {
                            "type": "dateFormat",
                            "attributes": {
                                "inputFormat": "yyyy-MM-dd",
                                "outputFormat": "ISO8601",
                                "input": {
                                    "type": "firstValid",
                                    "attributes": {
                                        "values": [
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CHGE Workday",
                                                    "attributeName": "HIRE_DATE__c"
                                                }
                                            },
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CLIENT NERM Contractors",
                                                    "attributeName": "Start_Date"
                                                }
                                            },
                                            "2000-01-01"
                                        ]
                                    }
                                }
                            }
                        }
                    }
                },
                "operator": "lte",
                "positiveCondition": "true",
                "negativeCondition": "false"
            }
        },
        "ifExpired": {
            "type": "dateCompare",
            "attributes": {
                "firstDate": {
                    "type": "dateMath",
                    "attributes": {
                        "expression": "+5d/d",
                        "roundUp": false,
                        "input": {
                            "type": "dateFormat",
                            "attributes": {
                                "inputFormat": "yyyy-MM-dd",
                                "outputFormat": "ISO8601",
                                "input": {
                                    "type": "firstValid",
                                    "attributes": {
                                        "values": [
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CHGE Workday",
                                                    "attributeName": "HIRE_DATE__c"
                                                }
                                            },
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CLIENT NERM Contractors",
                                                    "attributeName": "Start_Date"
                                                }
                                            },
                                            "2000-01-01"
                                        ]
                                    }
                                }
                            }
                        }
                    }
                },
                "secondDate": "now",
                "operator": "lte",
                "positiveCondition": "true",
                "negativeCondition": "false"
            }
        },
        "ifOneDayLeft": {
            "type": "dateCompare",
            "attributes": {
                "firstDate": {
                    "type": "dateMath",
                    "attributes": {
                        "expression": "+4d+5h",
                        "roundUp": false,
                        "input": {
                            "type": "dateFormat",
                            "attributes": {
                                "inputFormat": "yyyy-MM-dd",
                                "outputFormat": "ISO8601",
                                "input": {
                                    "type": "firstValid",
                                    "attributes": {
                                        "values": [
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CHGE Workday",
                                                    "attributeName": "HIRE_DATE__c"
                                                }
                                            },
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CLIENT NERM Contractors",
                                                    "attributeName": "Start_Date"
                                                }
                                            },
                                            "2000-01-01"
                                        ]
                                    }
                                }
                            }
                        }
                    }
                },
                "secondDate": "now",
                "operator": "lte",
                "positiveCondition": "true",
                "negativeCondition": "false"
            }
        },
        "ifTwoDaysLeft": {
            "type": "dateCompare",
            "attributes": {
                "firstDate": {
                    "type": "dateMath",
                    "attributes": {
                        "expression": "+3d+5h",
                        "roundUp": false,
                        "input": {
                            "type": "dateFormat",
                            "attributes": {
                                "inputFormat": "yyyy-MM-dd",
                                "outputFormat": "ISO8601",
                                "input": {
                                    "type": "firstValid",
                                    "attributes": {
                                        "values": [
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CHGE Workday",
                                                    "attributeName": "HIRE_DATE__c"
                                                }
                                            },
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CLIENT NERM Contractors",
                                                    "attributeName": "Start_Date"
                                                }
                                            },
                                            "2000-01-01"
                                        ]
                                    }
                                }
                            }
                        }
                    }
                },
                "secondDate": "now",
                "operator": "lte",
                "positiveCondition": "true",
                "negativeCondition": "false"
            }
        },
        "ifThreeDaysLeft": {
            "type": "dateCompare",
            "attributes": {
                "firstDate": {
                    "type": "dateMath",
                    "attributes": {
                        "expression": "+2d+5h",
                        "roundUp": false,
                        "input": {
                            "type": "dateFormat",
                            "attributes": {
                                "inputFormat": "yyyy-MM-dd",
                                "outputFormat": "ISO8601",
                                "input": {
                                    "type": "firstValid",
                                    "attributes": {
                                        "values": [
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CHGE Workday",
                                                    "attributeName": "HIRE_DATE__c"
                                                }
                                            },
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CLIENT NERM Contractors",
                                                    "attributeName": "Start_Date"
                                                }
                                            },
                                            "2000-01-01"
                                        ]
                                    }
                                }
                            }
                        }
                    }
                },
                "secondDate": "now",
                "operator": "lte",
                "positiveCondition": "true",
                "negativeCondition": "false"
            }
        },
        "ifFourDaysLeft": {
            "type": "dateCompare",
            "attributes": {
                "firstDate": {
                    "type": "dateMath",
                    "attributes": {
                        "expression": "+1d+5h",
                        "roundUp": false,
                        "input": {
                            "type": "dateFormat",
                            "attributes": {
                                "inputFormat": "yyyy-MM-dd",
                                "outputFormat": "ISO8601",
                                "input": {
                                    "type": "firstValid",
                                    "attributes": {
                                        "values": [
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CHGE Workday",
                                                    "attributeName": "HIRE_DATE__c"
                                                }
                                            },
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CLIENT NERM Contractors",
                                                    "attributeName": "Start_Date"
                                                }
                                            },
                                            "2000-01-01"
                                        ]
                                    }
                                }
                            }
                        }
                    }
                },
                "secondDate": "now",
                "operator": "lte",
                "positiveCondition": "true",
                "negativeCondition": "false"
            }
        },
        "ifFiveDaysLeft": {
            "type": "dateCompare",
            "attributes": {
                "firstDate": {
                    "type": "dateMath",
                    "attributes": {
                        "expression": "+0d+5h",
                        "roundUp": false,
                        "input": {
                            "type": "dateFormat",
                            "attributes": {
                                "inputFormat": "yyyy-MM-dd",
                                "outputFormat": "ISO8601",
                                "input": {
                                    "type": "firstValid",
                                    "attributes": {
                                        "values": [
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CHGE Workday",
                                                    "attributeName": "HIRE_DATE__c"
                                                }
                                            },
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "CLIENT NERM Contractors",
                                                    "attributeName": "Start_Date"
                                                }
                                            },
                                            "2000-01-01"
                                        ]
                                    }
                                }
                            }
                        }
                    }
                },
                "secondDate": "now",
                "operator": "lte",
                "positiveCondition": "true",
                "negativeCondition": "false"
            }
        },
        "value": "#if($lifecycleState==\"active\" && $adAccountCheck==\"ADFOUND\" && ($newJoinerCheck==\"true\" || $sameDayHireCheck==\"true\"))#if($ifExpired==\"true\")EXPIRED#elseif($ifOneDayLeft==\"true\")EXPIRESIN1DAY#elseif($ifTwoDaysLeft==\"true\")EXPIRESIN2DAYS#elseif($ifThreeDaysLeft==\"true\")EXPIRESIN3DAYS#elseif($ifFourDaysLeft==\"true\")EXPIRESIN4DAYS#elseif($ifFiveDaysLeft==\"true\")EXPIRESIN5DAYS#{else}FALSE#end#elseif($lifecycleState==\"active\" && $adAccountCheck==\"ADNOTFOUND\")$adAccountCheck#{else}FALSE#end"
    },
    "internal": false
}

Hey Sunny,

This problem can be fundamentally solved in a different way by creating an identity attribute called pwdLastSetDateType (it can be called whatever but must end in “DateType”) that is populated from your AD pwdLastSet value and apply a transform to change the date format:

{
    "name": "Win32 to ISO8601",
    "type": "dateFormat",
    "attributes": {
        "inputFormat": "EPOCH_TIME_WIN32",
        "outputFormat": "ISO8601"
    },
    "internal": false
}

From there, you can do direct date comparisons to a whole host of things and perform advanced date search operations on this attribute instead of it being a relatively static flag. Then, your workflow used to send password update reminder emails would execute on a daily frequency and check if pwdLastSetDateType > startDate + 5d (or whatever logic you need).

This simplifies things and prevents having to create a 445 line transform.

2 Likes

HI @sunnyajmera ,

I think this is because of HR aggregation and identity refresh are happening on different dates. E.g HR aggregation happens on 21/3 PM hrs and Identity refresh happens on 22/3 AM hrs. As this applies only one time (change in identity LCS)
So, try to change the operator only for “ifFiveDaysLeft” variable to “gte”. This ensures that “ifFiveDaysLeft” will be TRUE for HR aggregation and FALSE for identity refresh. For later identity refreshes, other logics will be applied correctly.

Did a quick test just now, you can get the date difference in integer in a static transform like this…just velocity:
"value": "#set($d1 = 1742710899)#set($d2 = 1743229286)#set($answer = ($d2-$d1) / 86400))Expires in $answer days"

i.e. That should cut down on your multiple if<x>DaysLeft variable formations.

…that is…if you still want to stick with your original implementation direction.

that’s a great idea, do you have any working that I can refer?

(The code example in the above post is something you can drop directly into a static transform, and you’ll see the result)

I don’t currently have the exact transformation that you have, but the idea is similar in the sense that it takes two dates, in epoch form, you evaluate which of the epoch is greater, and then do the epoch difference calculation, and use division to get the integer result (difference in days, the remainder is dropped in velocity).

You’ll still need to apply the other evaluation logic that you have, such as ADNOTFOUND…etc.

I imagine that fact you didn’t want to purely store the epoch values in attributes is that you want to retain some degree of human readability…so this would be the way. Dominick’s approach would work purely from a technical standpoint if you don’t need a human to read / understand what the attribute is about.

The usual velocity reference:
Apache Velocity Engine - User Guide

I’m finding that even without an offset, a common cause for this issue is how the date and time values are handled—especially if the source hire date doesn’t include a specific time (often defaulting to midnight). When compared to the current date/time, the lack of a time component on the hire date (or its default value) can result in the calculation appearing to be off by one day. This is compounded by the fact that “now” is computed with both date and time, so if your hire date is effectively midnight and your notification check runs later in the day, it might already satisfy a “less than or equal” condition that you intended to trigger the next day.
Explicitly Set the Time on the Hire Date: For example, you could convert the hire date to include a time of 00:00:00. If it already defaults to midnight
Check that both dates (the computed date from the hire date and now) are being compared at the same granularity (e.g., both rounded to the start of the day). You can use a dateMath transform to “round” the current date/time down to midnight (or your desired threshold) before comparing roun the hiredate and now date.

Thanks for the response. I agree that it’s not easy to identify an offset plus testing the change takes time too. I managed to identify the offset that worked in this case.

1 Like