Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Execute a Macro inside load script

Hi All,

is possible execute an Qlikview macro inside a load script?

Tks

16 Replies
marcel_olmo
Partner Ambassador
Partner Ambassador

Thanks for your suggestion.

Finally I've decided to create a .bat file which calls the QV document, adding a flag variable that tells the document to generate the xml files, reload the document, save it and finally close it.

Now works easily. Thanks!!

Not applicable
Author

HI Gordon,

  Hope u r fine,I used the code as placed in  your example

Function MonthDiff (startdate, enddate)

' return number of months between two dates

If IsDate(startdate) and IsDate(enddate) Then

MonthDiff = DateDiff("m", startdate, enddate)

End If

End Function

and try to invoke it in my script as follows

LET vExecFunction = MonthDiff(Date(AddMonths(Today(),-4)),Today());

and debug the script, I find vExecFunction variable holding null value

could you please let me know why it so.

Not applicable
Author

hi,

I have tried several things to make this work but it is not working. I have a funktion that should automatically send a mail.

I call my function in the load script like this.

let mail = sendMailTest();

this works fine if I open qv and press the load script button, but when I load the qvw in the management console it doesnt work can anyone explain me the reason why??

regards,

MT

Anonymous
Not applicable
Author

Hi MT,

Ive probably testing the same function. From the loading script a macro should be started and mail incl a pdf should be sent. I dont know why this is such a pain..

I heard sth about the OnPostReload Triggers. Maybe somehow it will work through triggers.

Unfortunately I dont find this "OnPost" trigger.

On execution trigger doesnt work in my case...

cheers chesterluck

Not applicable
Author

Srinivasan Rangaswamy

I am having a code which execute at the script and display the message at the vb Script (Both are haveing issue at the call code any Tought process/Guidence)



1. I am loading at the script and

2 showing the completed time at the vbscript message box.


here is my peace of code.Can any one of you help me out on this.


QV Script


LET vStart = num(now());

Store * from  FactTemp into FactTemp.qvd (qvd) ;

LET vRunTime = interval(now() - $(vStart),'mm:ss');

call alp(vRunTime) ;


VB Macro

function alp(vRunTime)

msgbox vRunTime;

end function


or
   consider this example

QV script


call alp(20)

vb script


function alp(vRunTime)

msgbox vRunTime

end function

Not applicable
Author

Hey Gordon Savage

I think the only reason why your example isn't working within my test application is because my Qlikview isn't recognizing DateDiff as a valid function. Despite that, your logic makes complete sense. In order to use the Macro Function in the Load Script, you call it like the following in the Load Script

Let vMonths = MonthDiff( Today(), Today() - 600)

I researched other sources and confirmed that you cannot utilize Macro Functions within Expressions on the front-end of Qlikview. In other words, I cannot utilize MonthDiff() in a Text Box.

This post contains an alternative function which worked in my application; it utilizes the same method, but a different macro function, which is why I believe the only reason MonthDiff() doesn't work is because of DateDiff() (Call VBA macro function from the load script | Lucian Cotea)

//Create this function in the Module

function Inc(Value)

Inc = Value+1

end function

//Use in Load Script

LET _VAR1 = Inc(1);

Last thing, there is no need to create a trigger for this macro in the document settings because it is a function. If it were a Sub, we'd need to create a trigger as mentioned previously.

I hope this helps!

cmccafferty
Contributor III
Contributor III

Hi, Can I piggyback onto this query.

I've created a function that works okay (see attached screenshots), but was hoping to have it execute whilst the script loads. Have I done it properly?

Thanks