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

Running a macro before a reload from the server

Hi everyone,

Here is my problem: I have a QVW which contains a macro that will fetch data from an internet file. After that macro runs, I need it to reload the document and save it. I do not want to use an OnOpen trigger or anything like that to kick off the macro, I just want to schedule a job to do it. Is there any preReload() function or anything similar? I am pretty experienced with the QV Desktop application, but I am new to the Server.

Thanks in advance for the help.

6 Replies
Not applicable
Author

I guess I could create a dummy QVW file with a blank script. And that file would reload nothing then run the macro with an OnPostReload trigger. Then have my application run after that one is done.

Is there a smarter, more efficient way to go about doing this?

Not applicable
Author

That is certainly an option. So it sounds like the data is being fetched and stored locally? Can it not be fetched dynamically in the load script ? Dont forget that if you reference a subroutine/function within the load script that isnt 'native' Qlikview it will look for a document macro and execute it if it finds it.

Regards,

Gordon

Not applicable
Author

Sorry for the poor explanation. The data isn't actually being fetched by the macro, or else I would load it in the script like you suggested. What the macro does is: it queries a website, and this website has a server that dynamically produces a txt file. The macro returns the LOCATION of the txt file as a VARIABLE, which is then used in my load statement to load the data. So that txt file is actually only being created when my macro runs, and then telling me where the file is.

So I need the macro to run in order to get the location of the data before the script runs.

Any ideas?

Not applicable
Author

Hi

Try this.

Add a variable to your script like vMacroRun. Set it to 1.

Set your macro to run on OnPostreload

In your script :

if vMacroRun = 1 then

// Do nothing

Set vMacroRun = 0; //

exit script;

else

// Your regular script

------

// Last line in script

Set vMacroRun = 1;

end if

1 Then make an External task and do a batchreload by using /r. Your macro will run and fetch LOCATION into the variable.

2. Do a regular load that is dependent on the first one being successful. The macro will not run since publisher will not execute it.

A little bit complicated but it should work fine.

Or just run the whole job as an External task fetching your variable on OnPostReload

Not applicable
Author

If the macro fetches the location, why can't you just use it as a function and load it directly in the script? For example in the load script:

LET a = getpath();

LOAD *
FROM $(a) (biff, embedded labels, table is Sheet1$);

where getpath is a function defined as:

Function GetPath ()
GetPath = "..\testfile.xls"
End Function

Regards,

Gordon

Not applicable
Author

gordon.savage

i want to execute this same script as vb macro. how about the possibility