Script works as notebook but not as task

Hello,
I get the error message “Failed to update task: failed to update task: option not found” when trying to save the following task.


The script executes without problems as notebook. The last two temperature values are compared and if the integer rounded value has changed an email is sent. Which “option” does the error message refer to?
Thanks for any hints.
Cheers,
SpeedY

Please don’t post code as an image. :-1:
Use a markdown code block instead and don’t forget to remove the secrets.

Hello Franky1,
Here is the Md version.

import "http"
import "json"
import "array"
import "influxdata/influxdb/secrets"
import "date"
import "math"

SENDINBLUE_APIKEY = secrets.get(key: ".?.")

getFieldValue = (tables=<-, field, offset) => {
  extract = tables
    |> tableFind(fn: (key) => key._field == field)
    |> getColumn(column: "_value")
  return extract[offset]
}

getTime = (tables=<-, field, offset) => {
  extract = tables
    |> top(n:1, columns: ["_time"])
    |> tableFind(fn: (key) => key._field == field)        
    |> getColumn(column: "_time")
  return extract[offset]
}

T_data = from(bucket: "...Bucket")
  |> range(start: -5m)
  |> aggregateWindow(every: 1m, fn: last, createEmpty: false)  
  |> getFieldValue(field: "Temperature_C",offset: 0)

T_datap = from(bucket: "...Bucket")
  |> range(start: -5m)
  |> aggregateWindow(every: 1m, fn: last, createEmpty: false)  
  |> getFieldValue(field: "Temperature_C",offset: 1)

H_data = from(bucket: "...Bucket")
  |> range(start: -5m)
  |> aggregateWindow(every: 1m, fn: last, createEmpty: false)
  |> getFieldValue(field: "Humidity_%", offset: 0)  

Tm_data = from(bucket: "...Bucket")
  |> range(start: -5m)
  |> aggregateWindow(every: 1m, fn: last, createEmpty: false)
  |> getTime(field: "Temperature_C", offset: 0)  

day = date.monthDay(t: Tm_data)
month = date.month(t: Tm_data)  
year = date.year(t: Tm_data)
hour = date.hour(t: Tm_data)
minute = date.minute(t: Tm_data)

T_changed = if math.ceil(x: T_data) != math.ceil(x: T_datap) then 1 else -1

resp = if T_changed == 1 then http.post(
        url: "https://api.sendinblue.com/v3/smtp/email",
        headers: {"accept": "application/json", "content-type": "application/json", "api-key": SENDINBLUE_APIKEY},
        data:
            json.encode(
                v: {
                    "to": [{"email": "..."}],
                    "sender": {"email": "..."},
                    "subject": "InfluxDB email test",
                    "textContent": "Hello again!\nOn ${day}.${month}.${year} at ${hour}:${minute} the temperature is ${T_data} ºC and the relative humidity is ${H_data} %.\nA minute before it was ${T_datap} ºC.\nCheers!",
                },
            ),
    ) else -1 

array.from(rows: [{_value: resp}])

@SpeedY To configure a task, InfluxDB uses the Flux task option. It’s missing from your current code. Just add something like the following below your import statements:

option task = {
    name: "Your task name",
    every: 5m // duration representing how often you want your task to run
}

In the UI, this usually gets added automatically using values from the form fields on the left. I’m not sure why that isn’t happening in your case.

Hello scott,
I suppose that the problem with the task option is the consequence of having modified an existing task.I generated a new task from scratch and this time the task option has been added correctly and the task runs without problems.
Cheers,
SpeedY