Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
sabreyals
Contributor III
Contributor III

Creating Qlikview scripts to trigger QVWs


Hi,

  I am trying to create a qlikview script that can run other scripts if and when a certain condition is satisfied.

The idea was to compare the maximum date from database for a table and compare it with the max date in the QVD.

If the difference between the dates is > 0 then i would run the execute command to refresh the QVD.

After i pick up the max dates this is what i am doing.

Let vDateInterval = AS_OF_DT - date(AS_OF_DT_QVD,'MM/DD/YYYY');

if( '$(vDateInterval)' > 0) then

execute "***.bat";

else

  exit script;

end if;

However when i debug the script i dont see any value in the vDateInterval variable and as a result my if-then-else doesnt seem to be working properly.

CAn any i done wrong here?

1 Solution

Accepted Solutions
Anonymous
Not applicable

Hi,

I think you are missing peek the values from the actual fields?

try:

Let vDateInterval = peek('AS_OF_DT', 0, 'FromTable') - date(peek('AS_OF_DT_QVD',0, 'From table') ,'MM/DD/YYYY');

This should work if you  have only one value in these fields (it gets the first one).

Best Regards

Stefan

View solution in original post

7 Replies
maxgro
MVP
MVP

I suppose it depends on AS_OF_DT and AS_OF_DT_QVD

Could you add some trace before Let statement and post the trace or the log?

Anonymous
Not applicable

Hi,

I think you are missing peek the values from the actual fields?

try:

Let vDateInterval = peek('AS_OF_DT', 0, 'FromTable') - date(peek('AS_OF_DT_QVD',0, 'From table') ,'MM/DD/YYYY');

This should work if you  have only one value in these fields (it gets the first one).

Best Regards

Stefan

sabreyals
Contributor III
Contributor III
Author

Hi Massimo,

  I used the trace statement like this

trace $(vDateInterval)

and here's what i got

10/14/2014 3:34:50 PM: 0036  Let vDateInterval =  peek(AS_OF_DT,0,'A') - date(peek(AS_OF_DT_QVD,0,'B'),'MM/DD/YYYY')
10/14/2014 3:34:50 PM: 0038  trace
10/14/2014 3:34:50 PM: 0038 

10/14/2014 3:34:50 PM:      Execution finished.

The variable doesnt seem to be holding any value.

If i create a list box in the document i am able to see the 2 date fields and their values. Any ideas?

sabreyals
Contributor III
Contributor III
Author

Hi Stefan,

  thanks for your reply. I am using the peek function now but still my variable sems to be empty.

Anonymous
Not applicable

Hi,

could please define a variable for each date field like:

let vDateInterval1 = peek('AS_OF_DT',0,'A');

let vDateInterval2 = peek('AS_OF_DT_QVD',0,'B');

and post the content of the variables after reloading your document. It's also possible the subtraction somehow doesn't work.

Best regards

Stefan

maxgro
MVP
MVP

I think you have some problems in AS_OF_DT and AS_OF_DT_QVD

Are these variables or fields? If variable trace it, maybe they are empty

If they are  variables, to get the max date from a qvd you should use something like (same suggestion as Stefan)

final:

load max(Orderdate) as Orderdate

from final.qvd (qvd);

vMaxOrderdate = peek('Orderdate');

trace $(vMaxOrderdate);

Post your script, if possible

sabreyals
Contributor III
Contributor III
Author

I missed out the single quotes for the field name, that is why my variables were holding a null value. Issue resolved now.

Other than Peek i came across another function called FieldValue which can be used in a similar way.

Thanks,