How to create Dynamic Date variable/constant to use in watch

786 Views Asked by At

I am trying to create a metadata field of type date to use in input, condition, action :

"metadata": { "range_start" : "now-10m" }

In the input it seems to have the desired effect.

In the action I am trying to use range_start like so:

from:{{ctx.metadata.range_start}},mode:absolute,to: {{ctx.trigger.triggered_time}}

but the result is:

(from:now-10m,mode:absolute,to:2018-01-11T10:38:27.509Z)

instead of:

(from:2018-01-11T10:28:27.509Z,mode:absolute,to:2018-01-11T10:38:27.509Z)

Any help is appreciated!

1

There are 1 best solutions below

1
On

I have done something similar with a transform in my watch

  "transform": {
"script": {
  "source": "def payload = ctx.payload; payload.calctime = Instant.ofEpochMilli(ctx.trigger.triggered_time.getMillis()).minusSeconds(600); return payload;",
  "lang": "painless"
}

Now you can reference the to and from time like this

from:'{{ctx.payload.calctime}}',mode:absolute,to:'{{ctx.trigger.triggered_time}}