# Find Latest Date Transform

**URL:** <https://developer.sailpoint.com/discuss/t/find-latest-date-transform/35207>\
**Category:** Transforms\
**Tags:** identity-security-cloud, transforms, community-developed\
**Created:** [March 13, 2024, 7:18pm UTC](https://developer.sailpoint.com/discuss/t/find-latest-date-transform/35207 "2024-03-13T19:18:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sup3rmark](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/sup3rmark/32/36229_2.png) [@sup3rmark](https://developer.sailpoint.com/discuss/u/sup3rmark)\
**Post date:** [March 13, 2024, 7:18pm UTC](https://developer.sailpoint.com/discuss/t/find-latest-date-transform/35207/1 "2024-03-13T19:18:26Z")

</div>

![Find Latest Date](https://global.discourse-cdn.com/sailpoint/original/2X/e/eeb4fd6e10321a300d3364b97f9d95dd5799ea2d.jpeg)

  

| | | |
| --- | --- | --- |
| 🗒 | **Description** | This transform compares multiple dates to determine which is the latest. |
| ⚖ | **Legal Agreement** | **By using this CoLabitem, you are agreeing to SailPoint’s [Terms of Service](https://developer.sailpoint.com/discuss/tos) for our developer community and open-source CoLab.** |
| 🛠 | **Repository Link** | [colab-transforms/transforms/find-latest-date/transform.json at 343bcea144c75eb7cd3e95c13550d780eab86a0c · sailpoint-oss/colab-transforms · GitHub](https://github.com/sailpoint-oss/colab-transforms/blob/343bcea144c75eb7cd3e95c13550d780eab86a0c/transforms/find-latest-date/transform.json) |
| 📖 | **New to Transforms in the CoLab?** | [Read the getting started guide for Transforms in the CoLab.](https://developer.sailpoint.com/discuss/t/getting-started-with-transforms-in-the-colab/13428) |
| 🏥 | **Supported by** | [Community Developed](https://developer.sailpoint.com/discuss/t/colab-support-models/17095#community-developed-busts_in_silhouette-3) |

# Overview

Use this transform to compare a list of dates to determine the latest date.

The following transform operations are used as well as the [Apache velocity templating language](https://velocity.apache.org/engine/1.7/user-guide.html) to accomplish this task.

- [accountAttribute](https://developer.sailpoint.com/docs/extensibility/transforms/operations/account-attribute)
- [dateFormat](https://developer.sailpoint.com/docs/extensibility/transforms/operations/date-format)
- [firstValid](https://developer.sailpoint.com/docs/extensibility/transforms/operations/first-valid)
- [static](https://developer.sailpoint.com/docs/extensibility/transforms/operations/static)

# Requirements

- Access to Identity Security Cloud

# Guide

With this transform you will be able to determine the latest date from the dates given.

The whole transform is wrapped in a [firstValid](https://developer.sailpoint.com/docs/extensibility/transforms/operations/first-valid) operation. This will ensure that our result will be our latest date or if something went wrong during processing the transform will return `null`.

The first item of the `firstValid` is where we setup and calculate the latest date using a couple different transform operations and the apache velocity templating language.

The first date `adLastLogin` is from an `Active Directory` source with the attribute name `lastLogon`. The transform pulls that value and converts it to the format `yyMMddHH` from it’s original epoch format. If there is an issue pulling that value, the transform will use the placeholder value of `125911584000000000` which equates to `January 1, 2000 12:00:00am`.

> **NOTE** :
> 
> - All dates should have the same fallback value.
> - The placeholder value used in the static operation needs to be adjusted for the inputFormat used so that the dateFormat operation can properly read and convert the date.

```json
 "adLastLogon": {
        "type": "dateFormat",
        "attributes": {
            "input": {
                "type": "firstValid",
                "attributes": {
                    "values": [
                        {
                            "type": "accountAttribute",
                            "attributes": {
                                "attributeName": "lastLogon",
                                "sourceName": "Active Directory"
                            }
                        },
                        {
                            "attributes": {
                                "value": "125911584000000000"
                            },
                            "type": "static"
                        }
                    ]
                }
            },
            "inputFormat": "EPOCH_TIME_WIN32",
            "outputFormat": "yyMMddHH"
        }
    }

```

Repeat this step until you have all of the dates you wish to compare. Make sure that you replace the `attributeName` and `sourceName` for each date.

> - The inputFormat of your date can be any supported format.
> - The outputFormat must always be `yyMMddHH`.

We must parse the dates as integers in order for the comparisons to work.

> **NOTE:**  
> Integers have a max value of `2147483647`. The values returned by `EPOCH_TIME_WIN32` and `EPOCH_TIME_JAVA` are both way beyond that. The transform needs something much, much smaller… but we can’t just create our own epoch time from a different year that we specify. This transform tries to find the last time an account was logged in so that an admin can determine whether it’s been inactive long enough to justify disabling it. In this example we use year-month-date-hour. A little bit of precision is lost here, but it’s good enough for this purpose. If you intend to implement similar logic, you will need to decide whether this level of precision is sufficient for your use case.

The main logic can be broken down as follows:

```bash
#set($max=-10) ## Instantiate a variable as an int; this will be our base for comparison as well as an int that will help us parse the dates as integers so we can compare them
#set($array = [$max.parseInt($adLastLogon),$max.parseInt($adLastLogonTimestamp),$max.parseInt($adPwdLastSet),$max.parseInt($adWhenCreated),$max.parseInt($azureLastInteractive),$max.parseInt($azureLastNonInteractive)]) ## Build an array of integers representing our dates
#foreach($val in $array) ## Iterate through the array
    #if($val > $max) ## Compare each value in the array against the current max value (which started at -10)
        #set($max = $val) ## If the current value is greater than the max, that value becomes the new max
    #end
#end
#if($max > 0) ## If the max value is greater than 0, return the max value
    $max
#end

```

---

<div class="post-metadata">

**Author:** ![jewalker](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@jewalker](https://developer.sailpoint.com/discuss/u/jewalker)\
**Post date:** [October 29, 2024, 8:19pm UTC](https://developer.sailpoint.com/discuss/t/find-latest-date-transform/35207/2 "2024-10-29T20:19:58Z")

</div>

Hello!

I can’t seem to get this transform to work in my environment. I consistently return null values despite keeping the transform very close to the same as what is in the github.

I have verified source names many times as well as the account schema. Also had a peer review this and we can’t figure out what’s missing unless the way these are processed changed somehow.

```auto
    "name": "LastActive",
    "type": "firstValid",
    "attributes": {
        "values": [
            {
                "type": "dateFormat",
                "attributes": {
                    "input": {
                        "type": "static",
                        "attributes": {
                            "adLastLogonTimestamp": {
                                "type": "dateFormat",
                                "attributes": {
                                    "input": {
                                        "type": "firstValid",
                                        "attributes": {
                                            "values": [
                                                {
                                                    "type": "accountAttribute",
                                                    "attributes": {
                                                        "attributeName": "lastLogonTimestamp",
                                                        "sourceName": "hcgg primary"
                                                    }
                                                },
                                                {
                                                    "attributes": {
                                                        "value": "125911584000000000"
                                                    },
                                                    "type": "static"
                                                }
                                            ]
                                        }
                                    },
                                    "inputFormat": "EPOCH_TIME_WIN32",
                                    "outputFormat": "yyMMddHH"
                                }
                            },
                            "adPwdLastSet": {
                                "type": "dateFormat",
                                "attributes": {
                                    "input": {
                                        "type": "firstValid",
                                        "attributes": {
                                            "values": [
                                                {
                                                    "type": "accountAttribute",
                                                    "attributes": {
                                                        "attributeName": "pwdLastSet",
                                                        "sourceName": "hcgg primary"
                                                    }
                                                },
                                                {
                                                    "attributes": {
                                                        "value": "125911584000000000"
                                                    },
                                                    "type": "static"
                                                }
                                            ]
                                        }
                                    },
                                    "inputFormat": "EPOCH_TIME_WIN32",
                                    "outputFormat": "yyMMddHH"
                                }
                            },
                            "adWhenCreated": {
                                "type": "dateFormat",
                                "attributes": {
                                    "input": {
                                        "type": "firstValid",
                                        "attributes": {
                                            "values": [
                                                {
                                                    "type": "accountAttribute",
                                                    "attributes": {
                                                        "attributeName": "whenCreated",
                                                        "sourceName": "hcgg primary"
                                                    }
                                                },
                                                {
                                                    "attributes": {
                                                        "value": "20000101010000.0Z"
                                                    },
                                                    "type": "static"
                                                }
                                            ]
                                        }
                                    },
                                    "inputFormat": "yyyyMMddHHmmss.S'Z'",
                                    "outputFormat": "yyMMddHH"
                                }
                            },
                            "azureLastInteractive": {
                                "type": "dateFormat",
                                "attributes": {
                                    "input": {
                                        "type": "firstValid",
                                        "attributes": {
                                            "values": [
                                                {
                                                    "type": "accountAttribute",
                                                    "attributes": {
                                                        "attributeName": "lastSignInDateTime",
                                                        "sourceName": "Azure AD Nonprod"
                                                    }
                                                },
                                                {
                                                    "attributes": {
                                                        "value": "2000-01-01T00:00:00Z"
                                                    },
                                                    "type": "static"
                                                }
                                            ]
                                        }
                                    },
                                    "inputFormat": "yyyy-MM-dd'T'HH:mm:ss'Z'",
                                    "outputFormat": "yyMMddHH"
                                }
                            }
                        },
                        "value": "#set($max=-10)#set($array=[$max.parseInt($adLastLogonTimestamp),$max.parseInt($adPwdLastSet),$max.parseInt($adWhenCreated),$max.parseInt($azureLastInteractive)])#foreach($val in $array)#if($val > $max)#set($max = $val)#end#end#if($max > 0)$max#end"
                    },
                    "inputFormat": "yyMMddHH",
                    "outputFormat": "ISO8601"
                }
            },
            null
        ]
    },
    "internal": false
}

```

Any help would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![sup3rmark](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/sup3rmark/32/36229_2.png) [@sup3rmark](https://developer.sailpoint.com/discuss/u/sup3rmark)\
**Post date:** [October 30, 2024, 3:19pm UTC](https://developer.sailpoint.com/discuss/t/find-latest-date-transform/35207/3 "2024-10-30T15:19:01Z")

</div>

try breaking each of those variables out into separate transforms and see if any of them are failing on their own. they should all be either `00010100` or an 8-digit string starting with `2`.

the only way a `null` value should be returned is if there’s an error being thrown by the velocity script, though it could be the case that since we’re converting to integers, the value returned by the velocity would be `10100` instead of `00010100` which could potentially be breaking on the `inputFormat` of `yyMMddHH` since it wouldn’t have enough characters… but this would only be the case if the identities you’re looking at don’t have values for any of the listed attributes, so this isn’t likely to be the issue.

---

<div class="post-metadata">

**Author:** ![jewalker](https://avatars.discourse-cdn.com/v4/letter/j/85e7bf/32.png) [@jewalker](https://developer.sailpoint.com/discuss/u/jewalker)\
**Post date:** [November 12, 2024, 4:28pm UTC](https://developer.sailpoint.com/discuss/t/find-latest-date-transform/35207/4 "2024-11-12T16:28:41Z")

</div>

This seemed to resolve the problem. Stepping through every section of the transform. Thank you!
