Date Compare/Date Math Transform error

Hi Everyone,
We have a requirement to modify the SNOW user account details after 90 days of user termination by appending the date in the following format yyyyMMdd_User_name.

I have created the following transform but getting this error - There was an exception while calculating the value for this attribute. Error during transformation for attribute: snowUsername. : DateMathTransform requires an input date or date expression with ‘now’

Any inputs would be appreciated!

 {
    "id": "",
    "name": "SNOW UserName TerminationDate Prefix",
    "type": "static",
    "attributes": {
        "dateCompareResult": {
            "type": "dateCompare",
            "attributes": {
                "firstDate": {
                    "type": "dateMath",
                    "attributes": {
                        "expression": "+90d",
                        "roundUp": false,
                        "input": {
                            "type": "dateFormat",
                            "attributes": {
                                "input": {
                                    "type": "firstValid",
                                    "attributes": {
                                        "values": [
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "Workday",
                                                    "attributeName": "TERMINATION_DATE"
                                                }
                                            },
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "Acquisitions - TEST",
                                                    "attributeName": "endDate"
                                                }
                                            },
                                       
                                            "12/23/2300"
                                        ]
                                    }
                                },
                                "inputFormat": "MM/dd/yyyy",
                                "outputFormat": "ISO8601"
                            }
                        }
                    }
                },
                "secondDate": "now",
                "operator": "lte",
                "positiveCondition": "yes",
                "negativeCondition": "no"
            }
        },
        "DatePrefixSnowUsername": {
            "type": "concat",
            "attributes": {
                "values": [
                    {
                        "type": "dateFormat",
                        "attributes": {
                            "input": {
                                "type": "firstValid",
                                "attributes": {
                                    "values": [
                                        {
                                            "type": "accountAttribute",
                                            "attributes": {
                                                "sourceName": "Workday",
                                                "attributeName": "TERMINATION_DATE"
                                            }
                                        },
                                        {
                                            "type": "accountAttribute",
                                            "attributes": {
                                                "sourceName": "Acquisitions - TEST",
                                                "attributeName": "endDate"
                                            }
                                        }
                                        }
                                    ]
                                }
                            },
                            "inputFormat": "MM/dd/yyyy",
                            "outputFormat": "ISO8601"
                        }
                    },
                    "_",
                    {
                        "type": "accountAttribute",
                        "attributes": {
                            "sourceName": "ServiceNow - QA",
                            "attributeName": "user_name"
                        }
                    }
                ]
            }
        },
        "SnowUserName": {
            "type": "firstValid",
            "attributes": {
                "values": [
                
                    {
                        "type": "accountAttribute",
                        "attributes": {
                            "sourceName": "ServiceNow",
                            "attributeName": "user_name"
                        }
                    },
                    {
                        "type": "accountAttribute",
                        "attributes": {
                            "sourceName": "ServiceNow - QA",
                            "attributeName": "user_name"
                        }
                    },
                    {
                        "type": "static",
                        "attributes": {
                            "value": "no-username"
                        }
                    }
                ]
            }
        },
        "cloudLifecycleState": {
            "attributes": {
                "name": "cloudLifecycleState"
            },
            "type": "identityAttribute"
        },
        "value": "#if($cloudLifecycleState == 'active')$SnowUserName#elseif($dateCompareResult == 'yes' && $cloudLifecycleState == 'inactive')$DatePrefixSnowUsername#{else}#end"
    },
    "internal": false
'''


Looks like you have an extra bracket in your code. I marked with with }.

{
    "id": "",
    "name": "SNOW UserName TerminationDate Prefix",
    "type": "static",
    "attributes": {
        "dateCompareResult": {
            "type": "dateCompare",
            "attributes": {
                "firstDate": {
                    "type": "dateMath",
                    "attributes": {
                        "expression": "+90d",
                        "roundUp": false,
                        "input": {
                            "type": "dateFormat",
                            "attributes": {
                                "input": {
                                    "type": "firstValid",
                                    "attributes": {
                                        "values": [
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "Workday",
                                                    "attributeName": "TERMINATION_DATE"
                                                }
                                            },
                                            {
                                                "type": "accountAttribute",
                                                "attributes": {
                                                    "sourceName": "Acquisitions - TEST",
                                                    "attributeName": "endDate"
                                                }
                                            },
                                       
                                            "12/23/2300"
                                        ]
                                    }
                                },
                                "inputFormat": "MM/dd/yyyy",
                                "outputFormat": "ISO8601"
                            }
                        }
                    }
                },
                "secondDate": "now",
                "operator": "lte",
                "positiveCondition": "yes",
                "negativeCondition": "no"
            }
        },
        "DatePrefixSnowUsername": {
            "type": "concat",
            "attributes": {
                "values": [
                    {
                        "type": "dateFormat",
                        "attributes": {
                            "input": {
                                "type": "firstValid",
                                "attributes": {
                                    "values": [
                                        {
                                            "type": "accountAttribute",
                                            "attributes": {
                                                "sourceName": "Workday",
                                                "attributeName": "TERMINATION_DATE"
                                            }
                                        },
                                        {
                                            "type": "accountAttribute",
                                            "attributes": {
                                                "sourceName": "Acquisitions - TEST",
                                                "attributeName": "endDate"
                                            }
                                        }
                                        **}**
                                    ]
                                }
                            },
                            "inputFormat": "MM/dd/yyyy",
                            "outputFormat": "ISO8601"
                        }
                    },
                    "_",
                    {
                        "type": "accountAttribute",
                        "attributes": {
                            "sourceName": "ServiceNow - QA",
                            "attributeName": "user_name"
                        }
                    }
                ]
            }
        },
        "SnowUserName": {
            "type": "firstValid",
            "attributes": {
                "values": [
                
                    {
                        "type": "accountAttribute",
                        "attributes": {
                            "sourceName": "ServiceNow",
                            "attributeName": "user_name"
                        }
                    },
                    {
                        "type": "accountAttribute",
                        "attributes": {
                            "sourceName": "ServiceNow - QA",
                            "attributeName": "user_name"
                        }
                    },
                    {
                        "type": "static",
                        "attributes": {
                            "value": "no-username"
                        }
                    }
                ]
            }
        },
        "cloudLifecycleState": {
            "attributes": {
                "name": "cloudLifecycleState"
            },
            "type": "identityAttribute"
        },
        "value": "#if($cloudLifecycleState == 'active')$SnowUserName#elseif($dateCompareResult == 'yes' && $cloudLifecycleState == 'inactive')$DatePrefixSnowUsername#{else}#end"
    },
    "internal": false
}

Thanks for looking. That was a typo. My original logic doesn’t have that.

Can you post the full error message?

Sure!
There was an exception while calculating the value for this attribute. Error during transformation for attribute: snowUsername (Transform ID: SNOW UserName TerminationDate Prefix) Cause: DateMathTransform requires an input date or date expression with ‘now’

The transform looks good. I was able to use it in my test environment with only a few minor tweaks to the accountAttribute calls.

I believe your issue is with:

{
    "type": "accountAttribute",
    "attributes": {
        "sourceName": "Acquisitions - TEST",
        "attributeName": "endDate"
    }
}

I am guessing it is returning a date in a different format than MM/dd/yyyy. Which would cause the dateFormat to fail, and cause dateMath to fail.

Yes, the issue was with the date input format. That fixed it. thank you!!

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.