Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Problem with running OnPostReload Macro from Command Line

Hello,

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 = "10.57.9.70"

          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

                        .Update

                              '---------------------------------------------------------------------

                    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 

                         objEmail.Send

          end if

          next  

          end if

          Set objFlds = Nothing

          Set objConf = Nothing

          Set objEmail = Nothing 

end function

7 Replies
erichshiino
Partner - Master
Partner - Master

Maybe this is a macro security issue:

Did you include the /nosecurity tag on the command line?

From the QV Reference Manual:

/NoSecurity

Overrides QlikView security measures against hostile macros and

scripts embedded in QlikView documents. No warning dialogs

prompting the user to accept potentially harmful code will be

shown. Use this switch with caution and only with well-known documents.

danielrozental
Master II
Master II

Also, you can add some message boxes to find out whether the macro gets triggered at all and to what steps it gets before freezing.

Not applicable
Author

Hi,

I tried both things you offered before I posted here

The /NoSecurity made no difference, about the message box I set one at the macro's start and it didn't pop so I'm guessing it doesn't start the macro at all.

I did however found an alternate solution, instead of using /r flag, Im using /l, then at the end of the macro added this command -

ActiveDocument.GetApplication.Quit

So once the macro is through, it closed the Qlikview (without save, but it's ok for my purpose).

It doesn't exacly solve my problem, but it satisfies my needs for now

Just out of curiousity, anyone has any idea why with /l it works OnPostReload, but with /r doesn't?

erichshiino
Partner - Master
Partner - Master

Very interesting solution! I guess that the /r may work like the server ( and the server does not call that trigger).

Both reload engines are the same... so that may be it.

Not applicable
Author

I have the same problem here using QV11 SR1 under 64 bit Windows 7, see attached app

The bat file just has this text in it.

"C:\Program Files\QlikView\QV.exe" /r /vRunit=1 C:\Clients\QVApps\AVale\Outlook_Mail_Send_Auto.qvw

It woks from the button but from the command line it does the reload and then it just stops. I have to kill the QV process to get the bat file to end. I am sure this used to work in earlier versions of QV and OS.

Any ideas?

Jane

Not applicable
Author

Has anyone gotten this working?

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

Command prompt:

qv.exe \l \ NoSecurity FileName.qvw

Your macro should be

SUB ReloadandGenerate

'

'

'

'

     ActiveDocument.Save

     ActiveDocument.GetApplication.Quit

END SUB

Regards,

Jagan.