Can ctx.execution_time be formatted in Watcher?

Hi,

I setup a Watcher and want to have a timestamp on email subject line, so I put ctx.execution_time, any way to format the ctx.execution_time like "2019-12-18 08:15 PM" or similar format date/time? Please advise.

Current result from my Watcher
Email Subject: Alert at 2019-12-18T03:47:14.683759Z

"actions": {
"send_email": {
"email": {
"from": "...",
"to": "...",
"subject": "Alert at {{ctx.execution_time}}",
"body": {
"html": "..."
}
}
}
}

You can use a script transform within the action to create a new field with a formatted date.

Thank you @spinscale, I am able to do something like this, and will test more options.

"transform" : {
"script" : "return [ 'time' : ctx.execution_time.getYear()+'-'+ctx.execution_time.getMonth()+'-'+ctx.execution_time.getDayOfMonth() ]"
}

great you got it working. you may want to take a look at explicit formatting in order to ensure you have two or four digit long numbers (think january first)...

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