PreHire User if set to be Joined in upcoming 7 days

I’m trying to set User Status as ‘PRE_HIRED’ if it is set to join in next 7 days but not able to conver it into transform.

below is something I reached upto, but surely I’m not able to mimic it after adding 7 days to current date or after subtracting it. Please help me with this usecase

"PRE_HIRE": {
			"attributes": {
				"firstDate": {
					"attributes": {
						"values": [
							{
								"attributes": {
                                    "input": {
                                        "attributes": {
                                            "expression": "-7d",
                                            "input": {
                                                "attributes": {
                                                    "input": {
                                                        "attributes": {
                                                            "attributeName": "LATEST_HIREDT",
                                                            "sourceName": "Delimited File"
                                                        },
                                                        "type": "accountAttribute"
                                                    },
                                                    "inputFormat": "ddMMyyyy",
                                                    "outputFormat": "ISO8601"
                                                },
                                                "type": "dateFormat"
                                            },
                                            "roundUp": true
                                        },
                                        "type": "dateMath"
                                    },
                                    "inputFormat": "yyyy-MM-dd'T'HH:mm",
                                    "outputFormat": "ISO8601"
                                },
								"type": "dateFormat"
							},
							{
								"attributes": {
									"input": "3112999",
									"inputFormat": "ddMMyyyy",
									"outputFormat": "ISO8601"
								},
								"type": "dateFormat"
							}
						]
					},
					"type": "firstValid"
				},
				"secondDate": {
					"type": "dateMath",
					"attributes": {
						"expression": "now",
						"roundUp": true
					}
				},
				"operator": "lte",
				"positiveCondition": "PRE_HIRED",
				"negativeCondition": "Inactive"
			},
			"type": "dateCompare"
		}

Hi @swapnil.kotwal,

Can you please describe what the results of this transform are? Is it throwing an error? Is every identity being set to inactive?

The transformation is working fine…

But, the issue is with logic. Since, I choose firstDate (lte) >= secondDate any old date (1 year old, 2 years old or more) evaluate the transform to ‘PRE_HIRED’ where my expectations are only users which are set to get hired within next 7 days should be marked as ‘Prehire’. I’m just ran out of thoughts how can I keep this logic within the 7 days window only.

See, attached screenshots. for the date 8102018 & 13092021 it always evaluate to ‘Prehire’


You need more than one date comparison to evaluate if the hire date is between today and 7 days from now. Since you only have one, you end up assigning all identities with a hire date older than 7 days from now the value PRE_HIRED. There’s a couple ways you could do this, but I think I have a solution that might work. Please note that I haven’t tested it, so let me know if it works for you.

This solution will perform two date comparisons, where the output of each date comparison is either true or false. It will then use a conditional to check that the output of both date comparisons are the same. In this case, we want to make sure the output of both are true. The two date comparisons are:

  • lesserDateCompare: (LATEST_HIREDT - 7d) <= now
  • greaterDateCompare: LATEST_HIREDT >= now

As long as both conditions evaluate to true, your LATEST_HIREDT is within 7 days, but not more or less. Because these are inclusive comparisons, they will never both be false. So, we just need a conditional to check that both results are true:

"expression": "$lesserDateCompare eq $greaterDateCompare"

The positive and negative condition of the above will be PRE_HIRED and Inactive, respectively.

Here is the untested code:

"PRE_HIRE": {
    "attributes": {
        "expression": "$lesserDateCompare eq $greaterDateCompare",
        "positiveCondition": "PRE_HIRED",
        "negativeCondition": "Inactive",
        "lesserDateCompare": {
            "attributes": {
                "firstDate": {
                    "attributes": {
                        "values": [
                            {
                                "attributes": {
                                    "input": {
                                        "attributes": {
                                            "expression": "-7d",
                                            "input": {
                                                "attributes": {
                                                    "input": {
                                                        "attributes": {
                                                            "attributeName": "LATEST_HIREDT",
                                                            "sourceName": "Delimited File"
                                                        },
                                                        "type": "accountAttribute"
                                                    },
                                                    "inputFormat": "ddMMyyyy",
                                                    "outputFormat": "ISO8601"
                                                },
                                                "type": "dateFormat"
                                            },
                                            "roundUp": true
                                        },
                                        "type": "dateMath"
                                    },
                                    "inputFormat": "yyyy-MM-dd'T'HH:mm",
                                    "outputFormat": "ISO8601"
                                },
                                "type": "dateFormat"
                            },
                            {
                                "attributes": {
                                    "input": "3112999",
                                    "inputFormat": "ddMMyyyy",
                                    "outputFormat": "ISO8601"
                                },
                                "type": "dateFormat"
                            }
                        ]
                    },
                    "type": "firstValid"
                },
                "secondDate": {
                    "type": "dateMath",
                    "attributes": {
                        "expression": "now",
                        "roundUp": true
                    }
                },
                "operator": "lte",
                "positiveCondition": "true",
                "negativeCondition": "false"
            },
            "type": "dateCompare"
        },
        "greaterDateCompare": {
            "attributes": {
                "firstDate": {
                    "attributes": {
                        "values": [
                            {
                                "attributes": {
                                    "input": {
                                        "attributes": {
                                            "attributeName": "LATEST_HIREDT",
                                            "sourceName": "Delimited File"
                                        },
                                        "type": "accountAttribute"
                                    },
                                    "inputFormat": "ddMMyyyy",
                                    "outputFormat": "ISO8601"
                                },
                                "type": "dateFormat"
                            },
                            {
                                "attributes": {
                                    "input": "3112999",
                                    "inputFormat": "ddMMyyyy",
                                    "outputFormat": "ISO8601"
                                },
                                "type": "dateFormat"
                            }
                        ]
                    },
                    "type": "firstValid"
                },
                "secondDate": {
                    "type": "dateMath",
                    "attributes": {
                        "expression": "now",
                        "roundUp": true
                    }
                },
                "operator": "gte",
                "positiveCondition": "true",
                "negativeCondition": "false"
            },
            "type": "dateCompare"
        }
    },
    "type": "conditional"
}
1 Like

Thank you so much @colin_mckibben , Seems like your logic is working fine… but expression comparison still have an issue…

This works well when

  1. both are ‘true’
  2. either one of them is ‘false’

but we have issue… when both evaluate to ‘false’ i.e.

$lesserDateCompare(false) eq $greaterDateCompare(false) evaluates to ‘true’ and that is incorrect, when both conditions are false, it still means the user is not Prehire

I’m thinking to tweak the expression as below. What do you think of it?

"expression": "($lesserDateCompare && $greaterDateCompare) && ($lesserDateCompare eq $greaterDateCompare)"

Oh, $lesserDateCompare and $greaterDateCompare in the form of string hence… ($lesserDateCompare && $greaterDateCompare) isn’t working though

I didn’t think there was a case where both would evaluate to false. Are you seeing an actual instance where both evaluate false? What value for LATEST_HIREDT is causing both to evaluate false?

Yes… if LATEST_HIREDT is empty then both of them evaluate to false

in case of empty we have used dummy values to avoid NPE $lesserDateCompare=31122999(greatest most dummy date) and $greaterDateCompare=31121999 (least most dummy date)… so this use case causes false for both the values

given the transform logic, if LATEST_HIREDT is empty and uses the ‘31122999’ value, then the conditions should evaluate as follows:

  • $lesserDateCompare = ‘31122999 - 7’ <= today == false
  • $greaterDateCompare = ‘31122999’ >= today == true

You’ll have to make sure your default value for LATEST_HIREDT is the same for both conditions, otherwise it will fail.

1 Like