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?

1 Solution

Accepted Solutions
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.

View solution in original post

19 Replies
petter
Partner - Champion III
Partner - Champion III

You can write this in JScript like this:

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 vExportTime2 = dt.getYear()+((m<10?'0':'')+ m)+((d<10?'0':'')+d)+' '+((hh<10?'0':'')+hh)+':'+((mm<10?'0':'')+mm)+':'+((ss<10?'0':'')+ss);

or this if you want a general padding function:

function padNum( n , separator ) {

  return ((n<10?'0':'') + n) + (separator==undefined?'':separator)

};

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 vExportTime1 = dt.getYear()+padNum(m)+padNum(d,' ')+padNum(hh,':')+padNum(mm,':')+padNum(ss);

dmohanty
Partner - Specialist
Partner - Specialist
Author

Now I understand petter.skjolden‌,

Thanks Much.

I am Setting a Path Variable (which is already in my script to store the QVD like this ), but failing here -

vRootFileLocation and vQVDs are already predefined in the Load Script and bringing in below.


Set vRootFileLocation = Activedocument.Variables("vRootFileLocation")

Set vQVDs = Activedocument.Variables("vQVDs")

obj.ExportEx (vRootFileLocationvQVDs&"Export_"&vDocName&vExportTime&".qvd" , ";" , 4)

dmohanty
Partner - Specialist
Partner - Specialist
Author

HI petter.skjolden‌ , petter-s

I changed the format to support in JScript, but still its failing here - -

obj.ExportEx ('vRootFileLocation\A.qvd', '4')


I have defeined the Variable like this -

var vRootFileLocation = ActiveDocument.Variables("vRootFileLocation")

obj = ActiveDocument.GetSheetObject("LB_Bookmark");

obj.ExportEx ('vRootFileLocation\A.qvd', '4')

petter
Partner - Champion III
Partner - Champion III

var doc = ActiveDocument;

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

obj = doc.GetSheetObject('CH01');

obj.ExportEx(vQVDs + 'myQVD.QVD' , 4 );

// Can be used on both a server - if the QVW is run on a server - and on a client if run locally with QlikView Desktop

obj.ServerSideExportEx( vQVDs + 'myQVD2.QVD' , '' , 4 );

dmohanty
Partner - Specialist
Partner - Specialist
Author

Thank you petter.skjolden‌ , petter-s

I tried like this below -

var doc = ActiveDocument; 

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

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

obj = doc.GetSheetObject('LB_Bookmark'); 

obj.ExportEx(vQVDs + 'Exp.QVD' , 4 );    

But getting error at last line - Object doesn't support this property or method

petter
Partner - Champion III
Partner - Champion III

You have to have a variable called vQVDs in your QlikView application already defined. This variable also has to return a string. The string has to end with a backslash. This code works well for me...

dmohanty
Partner - Specialist
Partner - Specialist
Author

Thank you petter.skjolden‌ , petter-s

I already have two predefined variables in my Script -

LET vRootFileLocation = GetRegistryString('HKEY_LOCAL_MACHINE\SOFTWARE\QlikView','RootFolderLocation');

Let vQVDs = '\QVDs\';

Still trying, if I am missing anything.

petter
Partner - Champion III
Partner - Champion III

What exactly does the vRootFileLocation contain?

dmohanty
Partner - Specialist
Partner - Specialist
Author

petter.skjolden‌ , petter-s‌,



vRootFileLocation  is the Server Path Name, that we are storing in Registry Files to be consistent across Environments (DEV,STG,PROD)


vRootFileLocation  = \\clientnetwork.net\Applications\OH001\QlikView\DataFilesStg\QlikView_Files\


vQVDs = '\QVDs\'


so finally, my QVD to be exported to  -

\\clientnetwork.net\Applications\OH001\QlikView\DataFilesStg\QlikView_Files\QVDs\