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: 
dmohanty
Partner - Specialist
Partner - Specialist

VBScript to JScript - Help in converting!

Hi petter-s ; petter.skjolden

Can you please help me here with one more please in converting from VBScript to JScript -

sub Export

vExportTime = Year(Now()) & Right("0" & Month(Now()), 2) & Right("0" & Day(Now()), 2) & " " & Right("0" & Hour(Now()), 2) & Right("0" & Minute(Now()), 2) & Right("0" & Second(Now()), 2)

 

set obj = ActiveDocument.GetSheetObject("LB98")

obj.ServerSideExportEx "C:\Users\dicky.mohanty\Documents\Bookmark Documents\Export_"&vExportTime&".qvd" , ";" , 4 '0=HTML, 1=Text, 2=Bitmap, 3=XML, 4=QVD, 5=BIFF

 

end sub

Also - Is it possible to use Relative Path/ Registry Path (for exporting into QVD) in Macro too, so as not to change them every time when we change environments from DEV to STG to PROD?

19 Replies
petter
Partner - Champion III
Partner - Champion III

I am not sure if ExportEx accepts UNC-paths in a file name at all. Try to save to a drive letter instead and see how that works....

dmohanty
Partner - Specialist
Partner - Specialist
Author

petter-s‌,

However the ServerSideExportEx (using VBScript) was successfully accepting the UNC Path and was storing.

Something strange and weird here it seems -

Its not storing , when I am using like this too --

obj = doc.GetSheetObject("LB_Bookmark");

obj.ExportEx('C:\Users\pa-dicky.mohanty\Documents\Exp.QVD',4);

dmohanty
Partner - Specialist
Partner - Specialist
Author

Hey petter-s‌ , petter.skjolden

Just to let you know -

UNC Path is accepted and now its storing the QVD perfectly. 

However, can you please help - how to store the QVD in a specific format? I want to append the values of the vDocName and vExportTime to the QVD and store them to make the QVDs unique.


Wanted to store QVD as Export_ExportDocument_20160405 165021.qvd

function Export() {

var dt = new Date();

var m = dt.getMonth()+1;

var d = dt.getDate();

var hh = dt.getHours();

var mm = dt.getMinutes();

var ss = dt.getSeconds();

var vExportTime = dt.getYear()+((m<10?'0':'')+ m)+((d<10?'0':'')+d)+' '+((hh<10?'0':'')+hh)+':'+((mm<10?'0':'')+mm)+':'+((ss<10?'0':'')+ss);

var doc = ActiveDocument;

var vDocName = doc.GetVariable('vDocName').GetContent().String;

var vRootFileLocation = doc.GetVariable('vRootFileLocation').GetContent().String; 

var vQVDs = doc.GetVariable('vQVDs').GetContent().String;

obj = doc.GetSheetObject("LB_Bookmark");

obj.ServerSideExport( vRootFileLocation + vQVDs +  'Export_"&vDocName&vExportTime&".qvd',4);

};

petter
Partner - Champion III
Partner - Champion III

Yes that should work well. But note that Javascript (JScript) does NOT use the & as a string concatenation operator. In Javascript you must use the + operator to concatenate strings.

obj.ServerSideExport( vRootFileLocation + vQVDs + 'Export_' + vDocName + vExportTime + '.qvd',4);

And you should not mix quote characters. Just use single quotes or just use double quotes. In Javascript it is optional which you use. In VBScript you have to use double quotes.

I prefer to always use single quotes with Javascript.

dmohanty
Partner - Specialist
Partner - Specialist
Author

Well petter-s, petter.skjolden

I tried a lot of Permutations and Combinations - and had already tried using the same way, as you have mentioned (either single quote or double quote).

When I am using the variable vDocName  - quickly it is getting stored as desired.

obj.ServerSideExport( vRootFileLocation + vQVDs + 'Export_' + vDocName +  '.qvd' , 4) ;

When I am using the variable vExportTime - it is taking time to execute and document hangs some time.

obj.ServerSideExport( vRootFileLocation + vQVDs + 'Export_' + vExportTime +  '.qvd' , 4) ;

Not sure why.

dmohanty
Partner - Specialist
Partner - Specialist
Author

Hey petter-s‌ , petter.skjolden‌,

Good News!

I used like this instead of the vExportTime  and it worked magically.

obj.ServerSideExport( vRootFileLocation + vQVDs + 'Export_' + vDocName + '_' + yr + m + d + hh + mm + ss + '.qvd' , 4) ;

petter
Partner - Champion III
Partner - Champion III

So you can mark the question as answered then...

dmohanty
Partner - Specialist
Partner - Specialist
Author

Hi petter-s‌, petter.skjolden

Surely I am going to mark it now as correct for your great help.

However, as small twist - The List Box is exporting all the records from it. I was expecting only the Possible/Selected Values only.

Any other script we need to add?

I am trying for some other changes to make it possible.

Not applicable

Instead of LB, create a Table Box with single filed and minimize the TB object. Try to export Table Box to QVD.

I just wondering what is use case storing LB to QVD?

tamilarasu
Champion
Champion

You can also try,

function Test()

{

currtime =  new Date();


  vYear        =       currtime.getFullYear();

  vMonth      =     ('0' + (currtime.getMonth()+1)).slice(-2);

  vDay        =      ('0' + (currtime.getDate())).slice(-2);

  vHour        =     ('0' + (currtime.getHours())).slice(-2);

  vMinute    =      ('0' + (currtime.getMinutes())).slice(-2);

  vSeconds  =     ('0' + (currtime.getSeconds())).slice(-2);

vExportTime = vYear + vMonth + vDay + " " + vHour + vMinute + vSeconds;

doc = ActiveDocument;

vRootFileLocation = doc.GetVariable('vRootFileLocation').GetContent().String;

vQVDs = doc.GetVariable('vQVDs').GetContent().String;

vDocName = doc.GetVariable('vDocName').GetContent().String;


obj = doc.GetSheetObject("LB_Bookmark");

obj.ServerSideExport( vRootFileLocation + vQVDs + "Export_" + vDocName + vExportTime + ".qvd",4);

};