# State trail problem

**URL:** <https://discourse.nodered.org/t/state-trail-problem/22783>\
**Category:** Dashboard\
**Created:** [8 March 2020 08:57 UTC](https://discourse.nodered.org/t/state-trail-problem/22783 "2020-03-08T08:57:11Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![olab](https://avatars.discourse-cdn.com/v4/letter/o/d07c76/32.png) [@olab](https://discourse.nodered.org/u/olab)\
**Post date:** [8 March 2020 08:57 UTC](https://discourse.nodered.org/t/state-trail-problem/22783/1 "2020-03-08T08:57:11Z")

</div>

I'm trying to make the state trail work based on planned task data from my MSSQL server, but it won't.

I cant find any error in my code. Can someone help?

![Capture2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/e/4e77013821776974d5aadd33ffec5a804bf3b3b9.png)

```auto
[{"id":"3b0e58f2.0a12b8","type":"MSSQL","z":"9a177fb4.e8284","mssqlCN":"c19a071f.c312d8","name":"","query":"SELECT\nDATEPART(YEAR, dtPlannedStart) As sYear,\nDATEPART(MONTH, dtPlannedStart)-1 As sMonth,\nDATEPART(DAY, dtPlannedStart) As sDate,\nDATEPART(HOUR, dtPlannedStart) As sHour,\nDATEPART(MINUTE, dtPlannedStart) As sMinute,\nDATEPART(SECOND, dtPlannedStart) As sSecond,\n\nDATEPART(YEAR, dtPlannedEnd) As eYear,\nDATEPART(MONTH, dtPlannedEnd)-1 As eMonth,\nDATEPART(DAY, dtPlannedEnd) As eDate,\nDATEPART(HOUR, dtPlannedEnd) As eHour,\nDATEPART(MINUTE, dtPlannedEnd) As eMinute,\nDATEPART(SECOND, dtPlannedEnd) As eSecond,\nplannedstart,\nplannedend\n\n\n\nFROM [TMBrumunddal].[dbo].[v_ProductionProgress] where ActualStart is null and Line in('PS 120')\norder by dtPlannedStart","outField":"payload","returnType":0,"throwErrors":1,"x":360,"y":180,"wires":[["4733b304.1c0f7c"]]},{"id":"29192e0e.bc05e2","type":"inject","z":"9a177fb4.e8284","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":180,"wires":[["3b0e58f2.0a12b8"]]},{"id":"5c7d0e72.fa3c1","type":"debug","z":"9a177fb4.e8284","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1010,"y":220,"wires":[]},{"id":"4733b304.1c0f7c","type":"function","z":"9a177fb4.e8284","name":"","func":"var data=[];\nvar sdate;\nvar edate;\n\n//loop through rows in SQL data\nfor(var i = 0; i < msg.payload.length; i++){\n \n sdate = new Date(\n msg.payload[i].sYear,\n msg.payload[i].sMonth,\n msg.payload[i].sDate,\n msg.payload[i].sHour,\n msg.payload[i].sMinute,\n 0,\n 0);\n \n \n \n edate = new Date(\n msg.payload[i].eYear,\n msg.payload[i].eMonth,\n msg.payload[i].eDate,\n msg.payload[i].eHour,\n msg.payload[i].eMinute,\n 0,\n 0);\n \n data.push({state:true,timestamp:sdate.getTime()});\n data.push({state:false,timestamp:edate.getTime()});\n}\n\n\n\nmsg.payload = JSON.stringify(data);\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":180,"wires":[["11964daa.091382"]]},{"id":"11964daa.091382","type":"change","z":"9a177fb4.e8284","name":"","rules":[{"t":"delete","p":"query","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":180,"wires":[["c4062f7a.ebf38","5c7d0e72.fa3c1"]]},{"id":"c4062f7a.ebf38","type":"ui_statetrail","z":"9a177fb4.e8284","group":"cee6ab9.ba30558","order":0,"width":0,"height":0,"name":"","label":"","states":[{"state":true,"col":"#009933","t":"bool","label":""},{"state":false,"col":"#999999","t":"bool","label":""}],"periodLimit":1,"periodLimitUnit":"3600","timeformat":"HH:mm:ss","tickmarks":4,"persist":false,"legend":1,"combine":true,"blanklabel":"","x":1020,"y":180,"wires":[[]]},{"id":"c19a071f.c312d8","type":"MSSQL-CN","z":"","tdsVersion":"7_4","name":"DB141004","server":"192.168.150.17","port":"1433","encyption":false,"database":"TMBrumunddal","useUTC":true,"connectTimeout":"15000","requestTimeout":"15000","cancelTimeout":"5000","pool":"5"},{"id":"cee6ab9.ba30558","type":"ui_group","z":"","name":"Group 1","tab":"618a128a.ebdb4c","order":1,"disp":false,"width":"23","collapse":false},{"id":"618a128a.ebdb4c","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

 ![Capture3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/392899802b09c11216e41deaac284c8da81a0bd3.png)

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [8 March 2020 10:47 UTC](https://discourse.nodered.org/t/state-trail-problem/22783/2 "2020-03-08T10:47:55Z")

</div>

Devide timestamps with 1000

---

<div class="post-metadata">

**Author:** ![olab](https://avatars.discourse-cdn.com/v4/letter/o/d07c76/32.png) [@olab](https://discourse.nodered.org/u/olab)\
**Post date:** [8 March 2020 12:24 UTC](https://discourse.nodered.org/t/state-trail-problem/22783/3 "2020-03-08T12:24:00Z")

</div>

Sorry, that didn't help.

Could it be someting about timestamps is in the future?

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [8 March 2020 13:38 UTC](https://discourse.nodered.org/t/state-trail-problem/22783/4 "2020-03-08T13:38:57Z")

</div>

Your timestamp format looks the same as mine;

```auto
{
"state": 1,
"timestamp": 1583651894208
},
{
"state": 2,
"timestamp": 1583653409178
},
{
"state": 1,
"timestamp": 1583653414181
},

```

> [@olab](#):
>
> Could it be someting about timestamps is in the future?

If you are inputting timestamps for some time in the future, the node config makes it clear that it only handles data from present time going backwards.  
i.e. Period **last** % seconds/minutes/hours  
So future timestamps would not be processed.

![state](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7f294c71cd38b4276e8cf269dfc5e6bb251e38fd.jpeg)

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [8 March 2020 13:49 UTC](https://discourse.nodered.org/t/state-trail-problem/22783/5 "2020-03-08T13:49:18Z")

</div>

This is something I haven't tried so can't even comment. If it's not working with future timestamps, it's not intentional restriction.

I'm still on the no computers weekend so can't check immediately

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [8 March 2020 14:09 UTC](https://discourse.nodered.org/t/state-trail-problem/22783/6 "2020-03-08T14:09:13Z")

</div>

Phones are powerful. Reading the code on github tells me that yes, future timestamp not supported. Will be supported tomorrow.

---

<div class="post-metadata">

**Author:** ![olab](https://avatars.discourse-cdn.com/v4/letter/o/d07c76/32.png) [@olab](https://discourse.nodered.org/u/olab)\
**Post date:** [8 March 2020 14:24 UTC](https://discourse.nodered.org/t/state-trail-problem/22783/7 "2020-03-08T14:24:11Z")

</div>

That is awsome!!

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [8 March 2020 18:13 UTC](https://discourse.nodered.org/t/state-trail-problem/22783/8 "2020-03-08T18:13:18Z")

</div>

Tomorrow is today and future is supported since now 🙃  
Version **0.2.12** available

---

<div class="post-metadata">

**Author:** ![olab](https://avatars.discourse-cdn.com/v4/letter/o/d07c76/32.png) [@olab](https://discourse.nodered.org/u/olab)\
**Post date:** [11 March 2020 06:47 UTC](https://discourse.nodered.org/t/state-trail-problem/22783/9 "2020-03-11T06:47:29Z")

</div>

Tank you, but it will still not work. It looks to me that the data fed into the node is correct. Timestamps has dates through the next week.

![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0ad45d93be35967297588afe1e85ee8956231b44.png) ![Capture1|329x168] ![Capture3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/a/aa38df54e61964054661ef787b76c90a6a332064.png)

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [11 March 2020 07:02 UTC](https://discourse.nodered.org/t/state-trail-problem/22783/10 "2020-03-11T07:02:24Z")

</div>

Your msg.payload is string

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b31907d67bdf88c145e4ff663e3bb85a14ae9707.png)

It needs to be an array of objects.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/a/3ac664b84ccf465a4cc27068b0303f6289d5b427.png)

---

<div class="post-metadata">

**Author:** ![olab](https://avatars.discourse-cdn.com/v4/letter/o/d07c76/32.png) [@olab](https://discourse.nodered.org/u/olab)\
**Post date:** [11 March 2020 11:59 UTC](https://discourse.nodered.org/t/state-trail-problem/22783/11 "2020-03-11T11:59:09Z")

</div>

Yess!

That solved my display problem bout would it be possible to get the time format as YYYY-MM-DD hh:mm or local time. Since my data stretches over a whole week it get a bit unreadable....

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [11 March 2020 12:05 UTC](https://discourse.nodered.org/t/state-trail-problem/22783/12 "2020-03-11T12:05:09Z")

</div>

It is possible, but as you can see, those strings will be pretty long so you can use less tickmarks and the left and right fading areas will be wider and active area therefore smaller. There must be some strategy figured out how to manage layout for long time marks. I don't have it right now and it may take some time.

---

<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:** [11 April 2020 03:28 UTC](https://discourse.nodered.org/t/state-trail-problem/22783/14 "2020-04-11T03:28:55Z")

</div>

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