Hey community,
I have an automation that gets all my automations via REST. In the response from the REST API call the date is formatted like this:
"created": 1727255448.771000000
My automation is creating Asset objects for each automation and I would like to have the attribute "Rule created" in my object type as a DateTime attribute.
I have tried to convert the value provided in the rest response to a format that goes into an Assets DateTime attribute but so far no luck.
Any tips or tricks how I can format my smart value in my automation to be accepted as a DateTime attribute in Assets?
Cheers,
// Svante
Hi @Svante Gustafsson Björkegren
The value is the number of seconds since the start of Unix time: the start of day on 1 January 1970.
To convert that for use as a date / time, the number could be multiplied by 1000 to convert to milliseconds and added to 1 Jan 1970. For example:
When I tested your amount, I got: 2024-09-25T09:10:48.7+0000
Kind regards,
Bill
Hey Bill,
Thnx for your solution, that worked perfect! I have a followup question on these DateTime values.
When I have converted the Unix time value from the REST response I would like to compare that DateTime with the DateTime stored in my Assets object. I have tried a number of different approaches but I can't get it right. Maybe you can identify what I am doing wrong here. I have attached two screenshots, one with the actions I have come up with and one from the audit log.
I think it is tricky to get the formats right.
Looking forward to hear back from you.
Cheers,
// Svante
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Svante Gustafsson Björkegren
I am glad to learn that helped!
Regarding the date / time comparisons, you are formatting the values with asLongDateTime and that converts them to text...preventing the function isAfter() from working: it expects a date or date / time type.
Please try removing the formatting to leave the values as date / time types for the comparison.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Bill Sheboy
I have removed the formattings as you suggested. Unfortunately, this didn't do the trick.
I have created a test automation for this where I convert a Unix timestamp to a DateTime, as you described. And then I lookup my Asset object and get the DateTime attribute.
When I try to compare these I only get empty strings as a result. Looking at the log it seems that they are of different formats. I am not sure if this is just a textual issue or if it is something else that makes them incompatible.
Do you have any idea why these two Dates cannot be compared?
Cheers,
// Svante
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It appears the asset value is a text representation of the date / time, and that needs to be converted with toDate prior to the comparison. Please try that first, and...
If that does not help, let's also try mitigating another possible problem: timing. My understanding is some asset data is looked up just-in-time, and so latency can cause problems with smart value expressions, rule actions, conditions, etc. The mitigation for that is to first store the value in a created variable to force full evaluation. Then the variable is used in later expressions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.