Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
dmohanty
Partner - Specialist
Partner - Specialist

VBScript to JScript - Is it possible?

Hi All,

I have a piece of VBScript code which is used as a macro. Can somehow it be converted to JScript?

The reason being, in that space, a lot of other JScripts are running and both VBScript and JScript are not supported at same time.

Here is the VBScript below. Please help.

SUB SelectValues
SET Doc = ActiveDocument
fieldName = "BookmarkFieldName"
SET Field = Doc.Fields(fieldName).GetPossibleValues

FOR index = 0 to Field.Count-1
Doc.Fields(fieldName).Clear
Doc.Fields(fieldName).SELECT Field.Item(index).Text   
fieldName1 = "BookmarkFieldValue"
SET Field1 = Doc.Fields(fieldName1 ).GetPossibleValues
  Doc.Fields(Field.Item(index).Text).SelectValues Field1
Doc.Fields(fieldName).Clear
NEXT
END SUB

1 Solution

Accepted Solutions
petter
Partner - Champion III
Partner - Champion III

This is the JavaScript equivalent of the VBScript:

function SelectValues() {

  doc = ActiveDocument;

  fieldName = 'BookmarkFieldName';

  field = doc.Fields(fieldName).GetPossibleValues();

  for ( index = 0; index <= field.Count - 1; index++) {

  doc.Fields(fieldName).Clear();

  doc.Fields(fieldName).Select( field.Item(index).Text );

  fieldName1 = 'BookmarkFieldValue';

  field1 = doc.Fields(fieldName1).GetPossibleValues();

  doc.Fields(field.Item(index).Text).SelectValues( field1 );

  doc.Fields(fieldName).Clear();

  };

};

View solution in original post

13 Replies
petter
Partner - Champion III
Partner - Champion III

This is the JavaScript equivalent of the VBScript:

function SelectValues() {

  doc = ActiveDocument;

  fieldName = 'BookmarkFieldName';

  field = doc.Fields(fieldName).GetPossibleValues();

  for ( index = 0; index <= field.Count - 1; index++) {

  doc.Fields(fieldName).Clear();

  doc.Fields(fieldName).Select( field.Item(index).Text );

  fieldName1 = 'BookmarkFieldValue';

  field1 = doc.Fields(fieldName1).GetPossibleValues();

  doc.Fields(field.Item(index).Text).SelectValues( field1 );

  doc.Fields(fieldName).Clear();

  };

};

dmohanty
Partner - Specialist
Partner - Specialist
Author

Hey petter.skjolden

This is amazing! A great help.

Many thanks and have a great day

dmohanty
Partner - Specialist
Partner - Specialist
Author

Hey petter.skjolden

Could you please help with this as well -

Sub AfterReload

  ActiveDocument.ReduceData

End Sub

petter
Partner - Champion III
Partner - Champion III

The translation into JavaScript (JScript) would look like this:

function AfterReload() {

     ActiveDocument.ReduceData();

};

And then you will have to add a trigger for OnPostReload and an action for this that is External / Run Macro and the name of this function as a parameter.

dmohanty
Partner - Specialist
Partner - Specialist
Author

Hey many many thanks petter.skjolden‌. This helped.

Also, I am working on a requirement and stuck at a point. By any means, could you help here please?

Here is the thread:

Re: Select &amp; Delete/Hide a value from List Box on Action of a Button - Help!

dmohanty
Partner - Specialist
Partner - Specialist
Author

Hey petter-s‌,

Please help in checking the below conversion from VBScript to JScript. I am getting an error to terminate with ';' .

sub ChartToQVD 

    set obj = ActiveDocument.GetSheetObject("CH01") 

    obj.ExportEx "BookmarkExportQVD.qvd", 4 

end sub

function ChartToQVD() {

obj = ActiveDocument.GetSheetObject("CH01") ;

obj.ExportEx 'BookmarkExportQVD.qvd', 4 ;

};

petter
Partner - Champion III
Partner - Champion III

JavaScript need ellipsis around it's parameters for the ExportEx method:

function ChartToQVD() {

    obj = ActiveDocument.GetSheetObject("CH01") ;

    obj.ExportEx('BookmarkExportQVD.qvd', 4) ;

};

dmohanty
Partner - Specialist
Partner - Specialist
Author

Yeah petter-s

Thank you so much. Now i understand.

Somehow these VBScript or JScript is not supported in AJAX. Are there any alternatives, you know?

dmohanty
Partner - Specialist
Partner - Specialist
Author

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