# Cron plus dynamic schedule on dashboard 2

**URL:** <https://discourse.nodered.org/t/cron-plus-dynamic-schedule-on-dashboard-2/85736>\
**Category:** General\
**Tags:** dashboard-2, cron-plus\
**Created:** [21 February 2024 14:58 UTC](https://discourse.nodered.org/t/cron-plus-dynamic-schedule-on-dashboard-2/85736 "2024-02-21T14:58:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [21 February 2024 14:58 UTC](https://discourse.nodered.org/t/cron-plus-dynamic-schedule-on-dashboard-2/85736/1 "2024-02-21T14:58:46Z")

</div>

Probably not specific to dashboard 2 but that's what I'm using so I threw that in. I have looked at all the examples imported and they work fine. I use what I think are the same settings in a function node and it doesn't setup a schedule. I am missing something spectacularly simple I think but after two long days I'm going to yell for help. If I use the example inject node it puts a schedule into cron. I can check that with the export schedule inject. If I inject the function node then use the export schedule there is no schedule. Here's my flow.

```auto
[{"id":"9ce844e480478dbd","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"c73de127c455c567","type":"cronplus","z":"9ce844e480478dbd","name":"","outputField":"payload","timeZone":"","storeName":"","commandResponseMsgOutput":"output1","defaultLocation":"","defaultLocationType":"default","outputs":1,"options":[],"x":600,"y":340,"wires":[["5b91e9dc82be1e6a"]]},{"id":"e94b58d201700f4c","type":"function","z":"9ce844e480478dbd","name":"Load Cron","func":"\nlet Z = flow.get(\"TempHr\");\nlet Y = flow.get(\"TempMin\");\nlet X = flow.get(\"TempPm\");\nlet W = flow.get(\"TempDay\");\n\nif (X == \"PM\"){\n Z = Z + 12;\n}\n\nmsg = \n{\n command: \"add\",\n name: \"every 20s Wed~Sun\",\n expression: \"*/20 * * * * 3-7 *\",\n payload: \"Hi wed~sun\",\n type: \"default\",\n limit: 3,\n topic: \"add\",\n}\n\nnode.status({fill:\"blue\",shape:\"dot\",text: msg.expression});\n\nreturn msg;\n/*\n\nmsg = \n{\n command: \"add\",\n name: \"every 20s Wed~Sun\",\n expression: \"0 \" + Y + \" \" + Z + \" ? * \" + W + \" *\",\n payload: \"Hi wed~sun\",\n type: \"default\",\n limit: 3,\n topic: \"add\",\n}\n\n*/","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":400,"wires":[["c73de127c455c567","5b91e9dc82be1e6a"]]},{"id":"6c510f0ec8aab0da","type":"inject","z":"9ce844e480478dbd","name":"Get list of schedules","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"list-all","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"list-all","payload":"","payloadType":"date","x":370,"y":120,"wires":[["c73de127c455c567"]]},{"id":"5b91e9dc82be1e6a","type":"debug","z":"9ce844e480478dbd","name":"debug 48","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":880,"y":340,"wires":[]},{"id":"6d25e5a3685511c8","type":"inject","z":"9ce844e480478dbd","name":"export all dynamic schedules","props":[{"p":"payload","v":"{\"command\":\"export-all-dynamic\"}","vt":"json"},{"p":"topic","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"command\":\"export-all-dynamic\"}","payloadType":"json","x":300,"y":200,"wires":[["c73de127c455c567"]]},{"id":"327841489ba3e79e","type":"inject","z":"9ce844e480478dbd","name":"add 3 schedules","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"command\":\"add\",\"name\":\"every 20s Wed~Sun\",\"expression\":\"*/20 * * * * 3-7 *\",\"payload\":\"Hi wed~sun\",\"type\":\"default\",\"limit\":3}","payloadType":"json","x":260,"y":260,"wires":[["c73de127c455c567","5b91e9dc82be1e6a"]]},{"id":"3578168ae0f5950a","type":"inject","z":"9ce844e480478dbd","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":210,"y":400,"wires":[["e94b58d201700f4c"]]},{"id":"ce79ee98d12a5ff6","type":"inject","z":"9ce844e480478dbd","name":"remove-all-dynamic","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"remove-all-dynamic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"remove-all-dynamic","payload":"","payloadType":"date","x":230,"y":340,"wires":[["c73de127c455c567"]]}]

```

Any help appreciated.  
here's the function node code by itself  
msg =  
{  
command: "add",  
name: "every 20s Wed~Sun",  
expression: "\*/20 \* \* \* \* 3-7 \*",  
payload: "Hi wed~sun",  
type: "default",  
limit: 3,  
topic: "add",  
}

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 February 2024 16:07 UTC](https://discourse.nodered.org/t/cron-plus-dynamic-schedule-on-dashboard-2/85736/2 "2024-02-21T16:07:49Z")

</div>

I have not used dynamic schedules, but looking in the help text I see this:  
**Adding one (or more) schedules**  
Example...

```auto
payload: [
  {
    "command": "add",
    "name": "every 6",
    "expression": "*/6 * * * * * *",
    "expressionType": "cron",
    "payloadType": "default",
    "limit": 3 
  },
  {
    "command": "add",
    "name": "new years eve 2030",
    "expression": "2030-01-01",
    "expressionType": "dates",
    "payloadType": "default"
  },
  {
    "command": "add",
    "name": "alarm1",
    "expressionType": "solar",
    "solarType": "selected",
    "solarEvents": "civilDawn,sunrise,sunset",
    "location": "54.999320540937035 -1.417407989501953",
    "offset": "-60",
    "payloadType": "str",
    "payload": "In 60 mins, it will be a great time to take photographs",
    "limit": null
  }
]

```

Which appears to be saying everything should be in msg.payload rather than the top level message. It is showing an array, but looking further down it suggests that it need not be an array if you are only adding one.

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [21 February 2024 16:20 UTC](https://discourse.nodered.org/t/cron-plus-dynamic-schedule-on-dashboard-2/85736/3 "2024-02-21T16:20:21Z")

</div>

Interesting, moving everything into msg.payload seems to work,  
Thanks

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 February 2024 16:22 UTC](https://discourse.nodered.org/t/cron-plus-dynamic-schedule-on-dashboard-2/85736/4 "2024-02-21T16:22:47Z")

</div>

> [@gerry](#):
>
> If I use the example inject node it puts a schedule into cron. I can check that with the export schedule inject. If I inject the function node then use the export schedule there is no schedule. Here's my flow.

You are setting the msg not the payload

change

```javascript
msg = {
    command: "add",
    name: "every 20s Wed~Sun",
    expression: "*/20 * * * * 3-7 *",
    payload: "Hi wed~sun",
    type: "default",
    limit: 3,
    topic: "add",
}

```

to

```javascript
msg.payload = {
    command: "add",
    name: "every 20s Wed~Sun",
    expression: "*/20 * * * * 3-7 *",
    payload: "Hi wed~sun",
    type: "default",
    limit: 3,
    topic: "add",
}

```

(or set payload to an array as Colin describes)

![chrome_D1LDdCq6KE](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b659e80f0b8e82615b31c4bdc09958dc498f680f.gif)

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [21 February 2024 16:25 UTC](https://discourse.nodered.org/t/cron-plus-dynamic-schedule-on-dashboard-2/85736/5 "2024-02-21T16:25:47Z")

</div>

I knew it had to be something irritatingly simple.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 March 2024 16:25 UTC](https://discourse.nodered.org/t/cron-plus-dynamic-schedule-on-dashboard-2/85736/6 "2024-03-06T16:25:56Z")

</div>

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