[{"id":"0df67d867ab6de33","type":"debug","z":"2380dbebb998c1d1","name":"Out func 2a","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1950,"y":1360,"wires":[]},{"id":"677fc548f7da5acd","type":"MSSQL","z":"2380dbebb998c1d1","mssqlCN":"6fb70e68d89e36c4","name":"","outField":"payload","returnType":"0","throwErrors":"0","query":"SELECT [dbo].[SCADENZIARIO].ID as ID_Scad,\n[dbo].[SCADENZIARIO].ID_STRUM,\nFORMAT( DATAULTIMOCONTROLLO, 'yyyy-MM-dd') as DATAULTIMOCONTROLLO,\n[dbo].[SCADENZIARIO].RESPONSABILE,\n[dbo].[SCADENZIARIO].STATO, \n[dbo].[StrumentazioneAttrezzature].ID,\n[dbo].[SCADENZIARIO].ALLEGATO, \n(case when [dbo].[SCADENZIARIO].ALLEGATO is not null then 1\n when [dbo].[SCADENZIARIO].ALLEGATO is null then 0\n end) as STATOALLEGATO,\n[dbo].[StrumentazioneAttrezzature].FREQUENZATARATURA, \n[dbo].[StrumentazioneAttrezzature].CODIFICA, \nFORMAT(dateadd(day,cast(FREQUENZATARATURA as int)-1, DATAULTIMOCONTROLLO),'yyyy-MM-dd') as DATASCADENZA,\n(case when [dbo].[SCADENZIARIO].STATO=1 then 'Done'\n when [dbo].[SCADENZIARIO].STATO is null then 'None'\n end) as STATON\n\nFROM [dbo].[SCADENZIARIO]\nINNER JOIN [dbo].[StrumentazioneAttrezzature]\nON [dbo].[SCADENZIARIO].ID_STRUM = [dbo].[StrumentazioneAttrezzature].ID\nWHERE [dbo].[StrumentazioneAttrezzature].CODIFICA = (@CODIFICA)","modeOpt":"","modeOptType":"query","queryOpt":"","queryOptType":"editor","paramsOpt":"","paramsOptType":"editor","rows":"","rowsType":"msg","params":[{"output":false,"name":"CODIFICA","type":"VarChar","valueType":"msg","value":"payload","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}}],"x":1700,"y":1420,"wires":[["0df67d867ab6de33","c197fb08b619e2aa","b7161d9eae43e31c","7b206d637cc3e465"]]},{"id":"c197fb08b619e2aa","type":"link out","z":"2380dbebb998c1d1","name":"Output Table Storico","mode":"link","links":["ccdeee0001de6a66"],"x":1895,"y":1420,"wires":[]},{"id":"b7161d9eae43e31c","type":"ui_template","z":"2380dbebb998c1d1","group":"82829bf25b86e4cd","name":"","order":8,"width":"4","height":"9","format":"\n<br/>\n<table id=\"table\" border=\"1\" height= 50px >\n\n <tr>\n <th>ID_ALLEG</th>\n <th>ALLEGATO</th> \n \n </tr>\n <tbody style=\"text-align: center\">\n <tr ng-repeat=\"x in msg.payload\">\n \n <td> {{x.ID_Scad}} </td>\n <td ng-if=\"x.STATOALLEGATO == 0\" > Not Available </td>\n <td ng-if=\"x.STATOALLEGATO == 1\"><a href=\"/report1\">Download Report</a>\n </tr>\n </tbody>\n</table>\n\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":1820,"y":1660,"wires":[["1c10caca4ddf9d25"]]},{"id":"1c10caca4ddf9d25","type":"debug","z":"2380dbebb998c1d1","name":"Out template","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2030,"y":1640,"wires":[]},{"id":"14cbec740920cd34","type":"function","z":"2380dbebb998c1d1","name":"Set base path","func":"\nvar basePath = \"/C:/Datamed/DB_Strumentazione/Node-red/Certificati/FileStreamDataFile/\";\nvar filepath = flow.get(\"filename_counter\");\n\n\nif (!filename) {\n msg.payload = \"No file specified\";\n msg.statusCode = 404;//not found\n return [null, msg];//fire output 2\n} else if(filename.includes(\"..\\\\\")){\n msg.payload = \"Illegal file path\";\n msg.statusCode = 405;//not allowed\n return [null, msg];//fire output 2\n} else if(filename.includes(\"../\")){\n msg.payload = \"Illegal file path\";\n msg.statusCode = 405;//not allowed\n return [null, msg];//fire output 2\n} \n\n\n//set msg.filename for the file in node\nmsg.filename = filepath;\n\n//get file name only & add it as the Content-Disposition header\nvar filename = filepath.split(\"/\").pop();\nmsg.headers = {\n \"Content-Disposition\": `attachment; filename=\"${filename}\"`\n}\n\nreturn [msg, null];//fire output 1\n\n\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1940,"y":1860,"wires":[["d716c36ab3415635","413c0db9fb4922e3"],["91de2a6759eea032"]]},{"id":"91de2a6759eea032","type":"http response","z":"2380dbebb998c1d1","name":"","statusCode":"","headers":{},"x":2150,"y":1940,"wires":[]},{"id":"d716c36ab3415635","type":"file in","z":"2380dbebb998c1d1","name":"","filename":"","format":"","chunk":false,"sendError":false,"encoding":"none","x":2150,"y":1860,"wires":[["91de2a6759eea032"]]},{"id":"91082eadc0605907","type":"catch","z":"2380dbebb998c1d1","name":"","scope":null,"uncaught":false,"x":1720,"y":1940,"wires":[["ae06ab5c8b64809f","5b4843bbb489c59a"]]},{"id":"ae06ab5c8b64809f","type":"function","z":"2380dbebb998c1d1","name":"Set 404","func":"msg.payload = msg.error;\nmsg.statusCode = 404;//resource not found\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1900,"y":1940,"wires":[["91de2a6759eea032"]]},{"id":"5b4843bbb489c59a","type":"debug","z":"2380dbebb998c1d1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1730,"y":2000,"wires":[]},{"id":"34bd000011a9f64d","type":"http in","z":"2380dbebb998c1d1","name":"","url":"/report1","method":"get","upload":false,"swaggerDoc":"","x":1710,"y":1860,"wires":[["14cbec740920cd34"]]},{"id":"7b206d637cc3e465","type":"change","z":"2380dbebb998c1d1","name":"","rules":[{"t":"set","p":"payload.ALLEGATO","pt":"msg","to":"filename_counter","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1620,"y":1700,"wires":[["1717dc4e4921011f"]]},{"id":"1717dc4e4921011f","type":"debug","z":"2380dbebb998c1d1","name":"filename","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1700,"y":1760,"wires":[]},{"id":"413c0db9fb4922e3","type":"debug","z":"2380dbebb998c1d1","name":"Out Path","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2100,"y":1760,"wires":[]},{"id":"6fb70e68d89e36c4","type":"MSSQL-CN","tdsVersion":"7_4","name":"DB_Strumentazione","server":"","port":"","encyption":true,"trustServerCertificate":true,"database":"DB_Strumentazione","useUTC":true,"connectTimeout":"","requestTimeout":"","cancelTimeout":"","pool":"","parseJSON":false,"enableArithAbort":true},{"id":"82829bf25b86e4cd","type":"ui_group","name":"Storico Date Controllo","tab":"21286fd2ee7bdc0c","order":6,"disp":true,"width":"20","collapse":false,"className":""},{"id":"21286fd2ee7bdc0c","type":"ui_tab","name":"Inserimento Date Controllo","icon":"assignment","order":4,"disabled":false,"hidden":true}]
A more complete flow looking at other post of the forum: