{"id":24960,"date":"2018-01-22T16:56:40","date_gmt":"2018-01-22T15:56:40","guid":{"rendered":"http:\/\/help.qualiware.it\/qw-help\/?p=24960"},"modified":"2024-03-19T18:12:05","modified_gmt":"2024-03-19T17:12:05","slug":"invio-di-un-messaggio-con-allegato-il-documento-e-i-documenti-collegati-zippati-bpm","status":"publish","type":"post","link":"https:\/\/help.qualiware.it\/qw-help\/invio-di-un-messaggio-con-allegato-il-documento-e-i-documenti-collegati-zippati-bpm\/","title":{"rendered":"Invio di un messaggio con allegato il documento e i documenti collegati zippati (BPM)"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">' Il seguente frammento di codice invia il file del documento e quelli dei documenti collegati in unico zip a destinatari appartenenti ad uno specifico ente.\r\n\r\n' Va a cercare i destinatari con ente  specifico, in esempio MD\r\nDim par3 As AssocArray = New AssocArray\r\nq3=OpenTable(DB,\"SELECT mail FROM PERSON WHERE mail is not null and (ente='MD' or ente2='MD' or ente3='MD' or ente4='MD' or ente5='MD')\",par3,false,false,msg3)\r\n\r\nif empty(msg3) and q3.rowset.first()\r\n\r\n\t'Se ci sono destinatari crea il messaggio\r\n\tDim qmail as QWMail = New QWMail\r\n\tqmail.MsgCreate()\r\n\t'Inserire il mittente\r\n\tqmail.MsgFrom(\"noreply@qualiware.it\")\r\n    do while not q3.rowset.endofset()\r\n\t'Vengono aggiunti come destinatari (TO)\r\n      qmail.MsgAddDest(q3.rowset.fields(1).value, 1)  \r\n\t  q3.rowset.next()\r\n\tloop  \r\n\t'Vengono definiti SOGGETTO e TESTO del messaggio\r\n\tSubj = \"Invio Documentazione - \" + formfields(\"TIPO_CONT\").Value + \"\/\" + formfields(\"NUMERO\").value\r\n\tTxt = \"In allegato documento e, ove presenti, i file collegati raccolti in un archivio zip. \"\r\n\tqmail.MsgSubject(Subj)\r\n\tqmail.MsgText(Txt)\r\n    ' La query prende il percorso e il nome estraendolo da NOMEFILE, che contiene anche altri elementi\r\n    Dim par As AssocArray = New AssocArray\t  \r\n\tsql=\"select NOMEFILE, substring(NOMEFILE, charindex('_-',NOMEFILE)+2,len(cast(NOMEFILE as varchar(300)))) as TITOLO from linkdoc where iddoc1='DW' and :CODDOC0 like coddoc1+'%' and iddoc2='**' \"\r\n\tpar(\"CODDOC0\")=CODDOC\r\n    q=OpenTable(DB,sql,par,false,false,msg)  \r\n\tif msg = \"\"\r\n\t if q.rowset.first() then\r\n \t  files = New DBArray\r\n\t  filenames = New DBArray\r\n         ' Crea un ciclo che va a prendere tutti i file associati e li mette nei vettori che saranno argomenti per la creazione  dello zip\r\n\t\tdo while not q.rowset.endofset() \r\n         ' file collegati\r\n\t\t\tnome=q.rowset.fields(\"nomefile\").value\r\n       '  report della registrazione - se si volesse mettere nello zip\r\n\t   '  nome= QWSess.Q95_NOME_DIR_DOCUM + \"\\\" + q.rowset.fields(\"DIRECTORY\").value+\"\\ATTESA\\\"+q.rowset.fields(\"NOMEFILE\").value\r\n\t\t\tIf File (nome) Then\r\n\t\t\t\tfiles.Add(nome)\r\n\t\t\t\tfilenames.Add(q.rowset.fields(\"TITOLO\").value)\r\n\t\t\tEnd If\r\n\t\t\tq.rowset.Next()\r\n\t\tloop\r\n\t\t' Terminata la raccolta degli allegati, si genera lo zip e lo si allega\r\n\t\tzipname = funique(Q95_PATH_TEMP + \"\\temp??????.zip\")\r\n\t\tDim zipper As qwlib.Zipper = New qwlib.Zipper\r\n\t\tzipper.GenerateZipFile(zipname, files, filenames)\r\n\t\tqmail.MsgAttachment(\"Allegati.zip\", zipname)\r\n\tend if  \r\n\tclosetable(q)\r\n end if\r\n    Dim par2 As AssocArray = New AssocArray\r\n \tsql2=\"select d.NOMEFILE,td.DIRECTORY, d.TITOLO, d.PUBBLICATO,d.tipo_cont, d.numero, d.custom1 FROM DOCUMENT d join TIPI_DOC td on d.TIPO=td.TIPO where d.OBSOLETO=0 and d._coddoc=:CODDOC \" \r\n\tpar2(\"CODDOC\")=CODDOC\r\n\tq2=OpenTable(DB,sql2,par2,false,false,msg2)  \r\n\t\t\r\n\tif msg2=\"\" and q2.rowset.first()\r\n\t\tif  q2.rowset.fields(\"PUBBLICATO\").value = true\r\n\t\t\tpercorsoreport = QWSess.Q95_NOME_DIR_DOCUM + \"\\\" + q2.rowset.fields(\"DIRECTORY\").value+\"\\DEFINITI\\\"+q2.rowset.fields(\"NOMEFILE\").value\r\n\t\telse\r\n\t\t\tpercorsoreport = QWSess.Q95_NOME_DIR_DOCUM + \"\\\" + q2.rowset.fields(\"DIRECTORY\").value+\"\\ATTESA\\\"+q2.rowset.fields(\"NOMEFILE\").value \r\n\t\tend if\r\n\t\t' Nome del file del documento nell'allegato\r\n\t\ttitolo = q2.rowset.fields(\"NOMEFILE\").value\r\n\t\t' Per sicurezza non tocco direttamente il file, ma lo copio in cartella temporanea\r\n\t\tpercorsocopia = Q95_PATH_TEMP + \"\\\" + titolo\r\n\t\tsystem.IO.file.copy(percorsoreport,percorsocopia,true)\r\n\t\tqmail.MsgAttachment(titolo,percorsocopia)\r\n\t\tmsg = \"\"\r\n\t\tok = qmail.MsgSend(msg)\r\n\t\tif ok = false then\r\n\t\t\tWriteLog(\"Messaggio non inviato: \" + msg)\r\n\t\t\telse\r\n\t\t\tWrite_LogDoc(QWSess,\"DW\",CODDOC,2,\"Messaggio con allegati zip e report inviato\")\r\n\t\tend if\r\n\tend if\r\n    CloseTable(q2)\t\t\r\nend if\r\nCloseTable(q3)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8216; Il seguente frammento di codice invia il file del documento e quelli dei documenti collegati in unico zip a destinatari appartenenti ad uno specifico ente. &#8216; Va a cercare i destinatari con ente specifico, in esempio MD Dim par3 As AssocArray = New AssocArray q3=OpenTable(DB,&#8221;SELECT mail FROM PERSON WHERE mail is not null and&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"ngg_post_thumbnail":0,"footnotes":""},"categories":[65],"tags":[69],"acf":[],"_links":{"self":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/24960"}],"collection":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/comments?post=24960"}],"version-history":[{"count":1,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/24960\/revisions"}],"predecessor-version":[{"id":36348,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/24960\/revisions\/36348"}],"wp:attachment":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/media?parent=24960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/categories?post=24960"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/tags?post=24960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}