Hi, now I have two problems:
1) var publicVariables = {
Data_START: "00:00:00", //this generate an error, I assume because it's not recognized as an hour
Lotto_START: "0",
Scheda_START: "0"
}
global.set("publicVariables", publicVariables);
return msg;
- No Output of payload with Calcola_Tempo calculated with:
var Calcola_Tempo = (msg.payload.Ora - publicVariables.Data_START);
This is the flow
[{"id":"98a22fb9.cb5a","type":"file in","z":"b1118599.3545f8","name":"Apri LOG DVC","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":340,"y":280,"wires":[["a25570de.29aed"]]},{"id":"ab3cd84c.703898","type":"change","z":"b1118599.3545f8","name":"C:\\LOG_QUADRA\\Storico","rules":[{"t":"set","p":"path","pt":"msg","to":"\\\\10.0.0.4\\c$\\LOG_QUADRA\\","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":220,"wires":[["91d240da.015f8"]]},{"id":"91d240da.015f8","type":"fs-ops-dir","z":"b1118599.3545f8","name":"","path":"path","pathType":"msg","filter":"*.log","filterType":"str","dir":"files","dirType":"msg","x":480,"y":220,"wires":[["2c369e2e.840132"]]},{"id":"2c369e2e.840132","type":"change","z":"b1118599.3545f8","name":"copy files to payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"files","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":220,"wires":[["12df3723.658b69"]]},{"id":"7266539f.9340cc","type":"function","z":"b1118599.3545f8","name":"make filename","func":"msg.file = msg.payload;\nmsg.filename = msg.path + \"\\\\\" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":140,"y":280,"wires":[["98a22fb9.cb5a"]]},{"id":"12df3723.658b69","type":"split","z":"b1118599.3545f8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":890,"y":220,"wires":[["7266539f.9340cc"]]},{"id":"a25570de.29aed","type":"csv","z":"b1118599.3545f8","name":"Split Fields","sep":";","hdrin":"","hdrout":false,"multi":"one","ret":"\\n","temp":"Giorno, Ora, Stato, Programma, Lotto, Scheda","skip":"0","strings":false,"x":530,"y":280,"wires":[["71d7613e.abfca"]]},{"id":"5194020f.43fdfc","type":"MSSQL","z":"b1118599.3545f8","mssqlCN":"e91a56e2.a1e9f8","name":"DVC to SQL","query":"insert into Output_Produzione (\n Centro_di_Lavoro, \n data, \n n_ord_prod, \n n_operazione, \n articolo, \n VarINT1,\n VarCHAR1,\n Tempo)\nVALUES (\n 1109,\n '{{{payload.DateTime}}}',\n '{{{payload.LottoRight5}}}',\n '{{{payload.LottoLeft4}}}',\n '{{{payload.Programma}}}',\n '{{{payload.Scheda}}}',\n '{{{payload.Stato}}}',\n '{{{payload.Tempo}}}')","outField":"payload","returnType":"0","throwErrors":"0","x":990,"y":280,"wires":[[]]},{"id":"71d7613e.abfca","type":"function","z":"b1118599.3545f8","name":"NEW transform DVC","func":"//copy of original payload for debug output\nmsg.origPayload = msg.payload;\n\n//make a copy of the row data... in some flows doesn't work ... WHY????\n//let row = {...msg.payload};\n\nif (msg.payload.Stato == \"START\"){\n //Store Data and Lotto of the \"START\" Record to calculate delta time with the \"END\" record\n global.set(publicVariables.Data_START, msg.payload.Ora);\n global.set(publicVariables.Lotto_START, msg.payload.Lotto);\n global.set(publicVariables.Scheda_START, msg.payload.Scheda);\n\n}\nelse {\n \n//If any condition is false, the record is skipped\n if (msg.payload.Stato == \"END\"){\n //recall public variables\n var publicVariables = global.get(\"publicVariables\");\n\n //Check if START lotto end END Lotto are the same\n if (msg.payload.Lotto == publicVariables.Lotto_START){\n //calculate delta time using the global variable Data_START\n var Calcola_Tempo = (msg.payload.Ora - publicVariables.Data_START);\n //calculate Quantity using the global variable Scheda_START\n var Calcola_Qta = (msg.payload.Scheda - publicVariables.Scheda_START);\n\n if (msg.payload.Lotto !== undefined){\n var WO = msg.payload.Lotto.substr(5,6);\n var OP = msg.payload.Lotto.substr(0,4);\n\n if (msg.payload.Programma !== undefined){\n var Prog = 'AP11'+ msg.payload.Programma;\n \n if (msg.payload.Scheda !== undefined){\n var Sch = msg.payload.Scheda;\n \n //solo se tutti gli IF sono andati a buon fine\n //preparo il messaggio\n \n var strG = msg.payload.Giorno;\n var strO = msg.payload.Ora;\n //split Data dd/mm/yyyy hh:mm:ss\n var D = strG.substr(6,4)+'/'+strG.substr(3,2)+'/'+strG.substr(0,2)+' '+strO;\n\n msg.payload = {\n a: 1109, //not sure what this is about?\n //DateTime: formatDT(row.Giorno, row.Ora), //Call a function to make the correct DATETIME string\n DateTime: D,\n //LottoRight5 : lottoParts[1], //characters right of the '/' \n //LottoLeft4: lottoParts[0], //characters left of the '/' \n LottoRight5 : WO,\n LottoLeft4 : OP,\n Stato: Status, //add Stato to the payload\n Programma: Prog, //add Programma to the payload\n Scheda: Sch, //add Scheda to the payload\n Tempo : Calcola_Tempo,\n Qta : Calcola_Qta\n }\n }\n \n }\n }\n }\n }\n\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":760,"y":280,"wires":[["2915102.0f697f"]]},{"id":"b64b201.b7b0ae","type":"inject","z":"b1118599.3545f8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":80,"y":140,"wires":[["69156b95.e64ca4"]]},{"id":"2915102.0f697f","type":"debug","z":"b1118599.3545f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":950,"y":340,"wires":[]},{"id":"69156b95.e64ca4","type":"function","z":"b1118599.3545f8","name":"Declare Global Variables","func":"var publicVariables = {\n Data_START: \"00:00:00\",\n Lotto_START: \"0\",\n Scheda_START: \"0\"\n}\nglobal.set(\"publicVariables\", publicVariables);\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":140,"wires":[["ab3cd84c.703898"]]},{"id":"e91a56e2.a1e9f8","type":"MSSQL-CN","z":"","tdsVersion":"7_4","name":"Scambio_NAV","server":"srv-dc","port":"1433","encyption":true,"database":"Scambio_NAV","useUTC":true,"connectTimeout":"90000","requestTimeout":"90000","cancelTimeout":"90000","pool":"5","parseJSON":false}]