Dynamic Expression for dateMath

Hi All,

Apologies if I’m way off the mark with this but I’m not making much progress with the docs or any existing topics. I’m new to IDN in general so I’m a bit out of my depth.

My identities have an endDate attribute (ISO8601 format) that I want to modify based on an identities timezone attribute (formatted as an expression for dateMath, i.e. if a user is in NYC their timezone attribute = “-5/h”).

I have tried to use nested transforms to achieve this but I am having no luck. Here is one of many attempts:

{
    "name": "Timezone endDate Modifier",  
    "type": "dateMath",
    "attributes": {
        "type": "static",
            "attributes": {
                "timeZoneMod": {
                    "attributes": {
                        "sourceName": "Employees",
                        "attributeName": "timezone"
                        },
                        "type": "accountAttribute"
                    },
                    "value": "$timeZoneMod"
            },
        "expression": "$timeZoneMod"
        }
}

Would anyone be able to advise me whether or not it is possible to use a dynamic expression for dateMath, and if so - what the best approach is?

Any help is much appreciated!

Hi Daniel

Yes, instead of using a dynamic expression for dateMath, try using the account attribute as the expression. One thing I noticed though in your description is you want to subtract 5 hours for NYC timezone with your dynamic expression equating to -5/h. This wouldn’t work as the expression to subtract 5 hours needs to be syntaxed like this “-5h”, the / would be added if you wanted to round up or down to an hour or second, e.g “-5h/s” would subtract 5 hours and round to the second.

Try something like this:

e.g where timezone = “-5h/s”

{
  "attributes": {
    "expression": {
                    "attributes": {
                        "sourceName": "Employees",
                        "attributeName": "timezone"
                        },
                        "type": "accountAttribute"
                    },
    "roundUp": true,
    "input": {
      "attributes": {
        "input": {
          "attributes": {
            "sourceName": "Employees",
            "attributeName": "endDate"
          },
          "type": "accountAttribute"
        },
        "inputFormat": "MMM dd yyyy, HH:mm:ss.SSS",
        "outputFormat": "ISO8601"
      },
      "type": "dateFormat"
    }
  },
  "type": "dateMath",
  "name": "Timezone endDate Modifier"
}

*adjust the input and output formats as needed or remove if not needed :slight_smile:

1 Like

Thanks Irshaad, this was the first type of solution I tried for the transform but I kept getting the error

There was an exception while calculating the value for this attribute. Attribute: ‘expression’ is missing for: DateMathTransform

Is that error perhaps due to the timezone being calculated after the endDate as opposed to me having the wrong transform format?

Edit: I should add that timezone is also calculated with a transform (table lookup)

I think in your case you are returning the string fromat of the date but date math expects the date to be in ISO8601 format.

Please refer to this document.

Thanks Ashutosh but as I called out in my post, all dates (specifically endDate here) are already in ISO8601 format before transforms apply. The issue I am having is with the expression, which is not a date

Edit: Ashutosh do you mean that when the attribute endDate is imported via source the account schema should be set to Int or Boolean and not string?

No. I saw the input coming from first valid and that i said has to in ISO.

For dynamic expression I do not think that is possible as the document just list specific commands that you can interchangeably use.

Probably you may use static transform using velocity expression to dynamically calculate the value.

Thanks

To all those that find this in the future, this solution worked. The error I referred to below when using this approach was because of the issue I had in another transform which was formatting the expression incorrectly

{
  "attributes": {
    "expression": {
                    "attributes": {
                        "sourceName": "Employees",
                        "attributeName": "timezone"
                        },
                        "type": "accountAttribute"
                    },
    "roundUp": true,
    "input": {
      "attributes": {
        "input": {
          "attributes": {
            "sourceName": "Employees",
            "attributeName": "endDate"
          },
          "type": "accountAttribute"
        },
        "inputFormat": "MMM dd yyyy, HH:mm:ss.SSS",
        "outputFormat": "ISO8601"

My transform to calculate the expression based on the country code had each output in the format +1/h instead of +1h/h (for hour roundup) or just +1h for no roundup.

    {
        "id": "4336883e-5be2-4363-8e04-5f0815b65fc2",
        "name": "Country to Timezone",
        "type": "lookup",
        "attributes": {
            "table": {
                "UK": "+1h",
                "USA": "-5h",
                "SGP": "+7h",
                "BEL": "+2h",
                "JPN": "+9h",
                "DEU": "+2h",
                "BRA": "-3h",
                "null": "+0h"
            }
        },
        "internal": false
    }

Thanks everyone for your help!

2 Likes

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