7 Replies Latest reply: Jun 30, 2014 12:19 AM by jagan mohan rao appala RSS

    Problem with running OnPostReload Macro from Command Line



      I'm have a model that checks if other models have been refreshed in the last hour, and send mail to the model's developer if they weren't.

      I have a macro that runs "OnPostReload" that sends the mails.

      If I open the model in Qlikview Desktop and reload it, it works fine.

      However, if I run it from command line, the model reloads (I see the script progress), but the macro doesn't work.

      In addition, the batch file hangs it remains open until I close it, and the qv.exe proccess stays open and I kill from task manager.


      Any ideas how to solve this?


      This is my macro:


      function sendMailFails()

        Dim objEmail

                Dim strMailTo


                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


                'Configure SMTP Server

                Const SMTPServer = ""

                Const SMTPPort = 25                             ' Port number for SMTP

                Const SMTPTimeout = 60                          ' Timeout for SMTP in seconds


         vNow= ActiveDocument.Variables("vNow").GetContent.String

                'Get Possible Values for recipients, models and last eun

                Set Recipient = ActiveDocument.Fields("Email").GetPossibleValues

                Set Model = ActiveDocument.Fields("Model").GetPossibleValues

                Set LastRun = ActiveDocument.Fields("LastRun").GetPossibleValues


                if Recipient.Count > 1 then 'Check if there's something to send


                'Define the email object

                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



                          End With


                objEmail.From = "Qlikview@pelephone.co.il"


                'for each model, set the recipient, subject and body, then send the report.

                for i = 0 to Model.Count -1

                if  Model.item(i).Text<>"Dummy" then

                               strMailTo = "" 'reset the to string

                               strMailTo = strMailTo & Recipient.item(i).Text & ";gyoav@pelephone.co.il"

                               objEmail.To = strMailTo

                               objEmail.Subject = Model.item(i).Text & " Not Running " &i

                               objEmail.TextBody = "Model " &          Model.item(i).Text & " didn't run since " & LastRun.item(i).Text & " Time now: " &vNow 


                end if



                end if


                Set objFlds = Nothing

                Set objConf = Nothing

                Set objEmail = Nothing 

      end function