Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

referencing the script code inside the code itself

Do you know if this is possible - to write a code that will search for certain string in the code I have written above, just like "find/search all Tabs" does .

More specifically I would like to get all my table names and the corresponding database table names and create an inline load with them automatically without exporting the script to file as I do now.

Sript has Tab Names and each Tab has Row No, so I wonder if it is possible to refer to these and write a code for a search-cycle.

if you know this, please share,

Thanks,

B.

5 Replies
Not applicable
Author

I did something similar in one of my documents.  I wanted to get table and field names.  Hopefully this will give you a start.

 

FOR i = NoOfTables()-1 to 0 STEP -1;

LET vTable = TableName($(i));

for j = NoOfFields('$(vTable)')-1 to 0 STEP -1;

  LOAD

   FieldName($(j),'$(vTable)') as TempDimName,

   '$(vTable)' as TempTableName

  AUTOGENERATE(1);

NEXT j;

NEXT i;

Not applicable
Author

That's a nice script, thanks. It'll give me the desired result if I postpone DROP TABLE statements for after this script  (in my script I load N tables Tab1, Tab2, .. TabN from N source tables - SourceTab1, SourceTab2, ..SourceTabN, to save each one separately in a qvd file and then drop it)

and IF I can get somehow the Source Table names for each TableName($(i)). I don't know how to do the last part, do you know if it is possible?

Also the first part - leaving Tables in RAM and drop all of them in the end will make my script less efficient and expose me to the risk to forget to drop some table. Anyway, if there is a function to get the Source Table names for eachTableName($(i)) I will do that.

Still I remain curious if referencing to the written script from inside the script itself is possible.

Thanks again for your answer.

B.

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

If you create a project folder for the qvw file, the script is automatically saved along with the rest of the layout whenever the qvw file is saved. To create a project folder, simply create a folder with the same name as the qvw file, with -prj appended to the end of the name.

So for the QV model file, mymodel.qvw, add a folder mymodel-prj in the same folder as the model. Open the model and save it to populate the folder. Now there will be a file named LoadScript.txt which is the load script. If you check the option Save Before Reload in the User Preferences | Save dialog, then the scipt will be resaved before each reload. You could then open the file in your script.

The data table lineage (the source data) is also stored (since QV10) in the XML header of the QVW (and also of QVD) files. This contains connection information, SQL scripts and/or source file names, spreadsheet sheet names etc. Search for MetaScan on this forum for more information.

Hope that helps

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Thanks for your answer. I have a hidden script, so it doesn't get exported in the LoadScript.txt.

As for Meta Scan I understand from the info on the forum that I need an additional application (MetaScanner Application) to acces this XML header info, is this correct?

B.

jonathandienst
Partner - Champion III
Partner - Champion III

B

Metascanner is a qvw application. Open it and have a look at the script and use that a starting point for your own.

Regards

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein