Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

send report error

hello, What is the problem in this code I can not have the correct file attached (I like ATT125.dat not attach my file (report)) thank you very much

function CriaReportPDF
'reportID = "RP01"
tempFolder = "c:"
Set SelectedReportID = ActiveDocument.Fields("reportID").GetPossibleValues
Set SelectedExportType = ActiveDocument.Fields("ExportTo").GetPossibleValues
Set SelectedExcelID = ActiveDocument.Fields("ExcelExportID").GetPossibleValues
Set SelectedReportName = ActiveDocument.Fields("reportName").GetPossibleValues


If SelectedReportID.count > 0 Then
If SelectedExportType.Item(0).Text ="PDF" Then
reportID = SelectedReportID.Item(0).Text
set rep = ActiveDocument.GetReport(reportID)
reportName = rep.Name

reportFile = tempFolder & reportName & ".pdf"
'PRINTING THE PDF FILE
printReportPDF reportID, reportFile
Else
ExcelID = SelectedExcelID.Item(0).Text

reportFile = tempFolder & SelectedReportName.Item(0).Text
'PRINTING THE EXCEL FILE
set obj = ActiveDocument.GetSheetObject(ExcelID)
obj.ExportBiff reportFile & ".xls"
reportFile = reportFile & ".xls"
End if

'CHECK IF THE FILE EXIST
checkOutputFile reportFile
'SEND THE MAIL with ATTACHMENT
'pdfmail reportFile
sendMailTest reportFile
End if
end function


function printReportPDF(oReport, pdfOutputFile)
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKCU\Software\QlikViewPDF\OutputFile", pdfOutputFile, "REG_SZ"
WSHShell.RegWrite "HKCU\Software\QlikViewPDF\BypassSaveAs", "1", "REG_SZ"
'QV Print
ActiveDocument.PrintReport oReport, "QlikViewPDF", false
set WSHShell = nothing
end function


function checkOutputFile(pdfFile)
Set fileTest = CreateObject("Scripting.FileSystemObject")
currentStatus = fileTest.FileExists (pdfFile)

if currentStatus = false then
rem ** let QV sleep for 1 seconds **
ActiveDocument.GetApplication.sleep 1000
checkOutputFile(pdfFile)
end if

set fileTest = nothing
end function





function sendMailTest(pdfFile)
Dim objEmail

Const cdoSendUsingPort = 2 ' Send the message using SMTP

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM


Const SMTPServer = "Your_smtp.com"
Const SMTPPort = 25 ' Port number for SMTP
Const SMTPTimeout = 60 ' Timeout for SMTP in seconds


'Sending mail
strMailattach = pdfFile
Set objEmail = CreateObject("CDO.Message")
Set objConf = objEmail.Configuration
Set objFlds = objConf.Fields
With objFlds
'---------------------------------------------------------------------
' SMTP server details
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = SMTPTimeout
.Update
'---------------------------------------------------------------------
End With

'Add Subject
strSubject = getvariable("mailSubject")
if strSubject ="" then
strSubject = "QlikView Sales Dashboard"
End if

'Add the body
strMsg = getvariable("mailbody")
if strMsg = "" then
strMsg = "Please find attached the Details Sales Dashboard. This is a System generated mail from QlikView"
End if

objEmail.To = getvariable("mlto") 'Email Recipient
objEmail.From = "admin@QlikView.com" 'Email Sender
objEmail.Subject = strSubject ' Subject
objEmail.TextBody = strMsg 'Text Body


objEmail.AddAttachment strMailattach

objEmail.Send

Set objFlds = Nothing
Set objConf = Nothing
Set objEmail = Nothing

deleteReport strMailattach

msgbox ("Mail Sent Succesfully")

end function


function deleteReport(rFile)
set oFile = createObject("Scripting.FileSystemObject")

currentStatus = oFile.FileExists(rFile)

if currentStatus = true then
oFile.DeleteFile(rFile)
end if
set oFile = Nothing
end function



function getVariable(varName)
set v = ActiveDocument.Variables(varName)
getVariable = v.GetContent.String
end function
0 Replies