Iterating on a post I made about 6 weeks ago with a different way to achieve the same goal!
I wanted to expand on my previous transform (which looks at the AD LastLogon
and LastLogonTimestamp
attributes, as well as the AzureAD/EntraID lastSignInDateTime
and lastNonInteractiveSignInDateTime
attributes), to also pull in the AD pwdLastSet
attribute as well as the AD whenCreated
attribute. Because comparing 6 values using if
statements would be cumbersome and even uglier than comparing 4 values was, I decided to dive back into Velocity to try and figure out a better way.
Now, through the magic of arrays and foreach
loops, Iāve found one!
Iāve simplified my previous transform a bit (by removing the essentially duplicated values to maintain the to-the-minute accuracy) while also adding the two additional attributes, and am now returning null
values rather than error
when a value couldnāt be determined.
The transform:
{
"name": "mc-LastActiveDate",
"type": "firstValid",
"attributes": {
"values": [
{
"type": "dateFormat",
"attributes": {
"input": {
"type": "static",
"attributes": {
"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"
}
},
"adLastLogonTimestamp": {
"type": "dateFormat",
"attributes": {
"input": {
"type": "firstValid",
"attributes": {
"values": [
{
"type": "accountAttribute",
"attributes": {
"attributeName": "lastLogonTimestamp",
"sourceName": "Active Directory"
}
},
{
"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": "Active Directory"
}
},
{
"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": "Active Directory"
}
},
{
"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 Active Directory"
}
},
{
"attributes": {
"value": "2000-01-01T00:00:00Z"
},
"type": "static"
}
]
}
},
"inputFormat": "yyyy-MM-dd'T'HH:mm:ss'Z'",
"outputFormat": "yyMMddHH"
}
},
"azureLastNonInteractive": {
"type": "dateFormat",
"attributes": {
"input": {
"type": "firstValid",
"attributes": {
"values": [
{
"type": "accountAttribute",
"attributes": {
"attributeName": "lastNonInteractiveSignInDateTime",
"sourceName": "Azure Active Directory"
}
},
{
"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($adLastLogon),$max.parseInt($adLastLogonTimestamp),$max.parseInt($adPwdLastSet),$max.parseInt($adWhenCreated),$max.parseInt($azureLastInteractive),$max.parseInt($azureLastNonInteractive)])#foreach($val in $array)#if($val > $max)#set($max = $val)#end#end#if($max > 0)$max#end"
}
},
"inputFormat": "yyMMddHH",
"outputFormat": "ISO8601"
}
},
null
]
},
"internal": false
}
The main logic can be broken down as follows. Remember we have to parse the dates as integers in order for the comparisons to work:
#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
Shout-out to @tyler_mairose and @brennenscott for various bits of inspiration!